菜鸟求问
import java.util.Properties;怎么作?实现显示第几次运行 java 类 应用 --------------------编程问答-------------------- --------------------编程问答-------------------- 运行一次,修改文件的值,再读出来,貌似是这么做 --------------------编程问答-------------------- 你这想法不是挺好的么。。。
import java.io.*;
import java.net.URI;
import java.net.URISyntaxException;
import java.net.URL;
public class PropertiesFile {
/**
* @throws IOException
* @
*/
public static void main(String[] args) throws IOException {
Properties settings = new Properties();
FileInputStream count = null;
try {
count = new FileInputStream(new File(new URI("file:///d:/count.txt")));
} catch (URISyntaxException e) {
// TODO Auto-generated catch block
settings.setProperty("count",String.valueOf(0));
}
settings.load(count);
int c = Integer.parseInt(settings.getProperty("count"))+1;
System.out.println("这是第" + c + "次运行!!!!!");
settings.setProperty("count",new Integer(c).toString());
settings.store(new FileOutputStream("file:///d:/count.txt"), "程序被应用!!!!!");
}
}
试试
settings.store(new FileOutputStream("d:/count.txt"), "程序被应用!!!!!");
补充:Java , Eclipse