我使用的MyEclipse版本其实已经很旧了,是6.5的,每天打开时都要看到相同的这张图片
也许因为喜新厌旧的本性吧,想把这图换掉,而且最好每天都不同。
查了一下,比较合理的方法修改MyEclipse 6.5\eclipse\eclipse.ini这个文件。
用文本编译器打开后在最后增加类似 -Dosgi.splashLocation=C:\Documents and Settings\Administrator\桌面\ChangeSplsh\image\w2.bmp 这样一句话
既然有这么轻巧的配置方式,之后的事情就顺水推舟了。
编写了一个修改文本信息的类,源码如下:
package org;
import java.io.BufferedInputStream;
import java.io.BufferedReader;
import java.io.File;
import java.io.FileInputStream;
import java.io.FileOutputStream;
import java.io.IOException;
import java.io.InputStreamReader;
import java.io.PrintWriter;
import java.util.Calendar;
import java.util.Date;
import java.util.Properties;
public class Change {
public static void function() throws IOException {
}
public static void main(String[] args) throws IOException {
//获得真实路径
String userDir=System.getProperty("user.dir");
//获得文件分隔符(在 UNIX 系统中是“/”)
String separator=System.getProperty("file.separator");
//从配置文件中读取eclipse.ini文件的路径
Properties properties=new Properties();
BufferedInputStream bis=new BufferedInputStream(new FileInputStream(userDir+separator+"path.properties"));
properties.load(bis);
String path=(String) properties.get("path");
System.out.println("配置文件路径为"+path);
//组合图片路径
String imgPath=userDir+separator+"image"+separator+"w"+getWeek()+".bmp";
String oldStr="-Dosgi.splashLocation=";
String replaceStr="-Dosgi.splashLocation="+imgPath;
System.out.println("图片路径为"+imgPath);
replaceTxtByStr(path,oldStr,replaceStr);
}
/**
* 今天星期几
*
* @retun
* @createTime 2012/04/13
* @lastModifyTime 2012/04/13
*/
private static int getWeek() {
Calendar cal=Calendar.getInstance();
return cal.get(Calendar.DAY_OF_WEEK)-1;
}
/**
* 文本文件中指定字符串的第一行替换为其他字符串
*
* @param oldStr
* @param replaceStr
* @createTime 2012/04/13
* @lastModifyTime 2012/04/13
*/
public static void replaceTxtByStr(String path,String oldStr,String replaceStr) throws IOException{
String temp="";
File file=new File(path);
BufferedReader br=new BufferedReader(new InputStreamReader(new FileInputStream(file)));
StringBuffer sb=new StringBuffer();
//保存该行前面的内容
for(int i=1;(temp=br.readLine())!=null&&!(temp.indexOf(oldStr)>-1);i++) {
sb.append(temp);
sb.append(System.getProperty("line.separator")); //获得行分隔符
}
//将内容插入
sb.append(replaceStr);
//保存该行后面的内容
while((temp=br.readLine())!=null) {
sb.append(System.getProperty("line.separator"));
sb.append(temp);
}
br.close();
PrintWriter pw=new PrintWriter(new FileOutputStream(file));
pw.write(sb.toString().toCharArray());
// pw.print(sb.toString());
pw.flush();
pw.close();
}
}
效果就是,每天执行时根据星期信息修改配置文件,更改开启图片
放张截图