更改MyEclipse开启时的图片

我使用的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();
	}
}



效果就是,每天执行时根据星期信息修改配置文件,更改开启图片


放张截图


源代码:http://download.csdn.net/detail/w93223010/4515828

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 1
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论 1
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值