本帖最后由 JavaProgrammer 于 2015-10-5 14:32 编辑
import java.io.FileReader;
import java.io.IOException;
import java.io.PrintStream;
import java.util.Properties;
public class Properties_Test2 {
public static void main(String[] args) throws IOException {
Properties p = new Properties();
p.load(new FileReader("D:/Program Files/Workspace/IO/properties.txt"));
//提前在D:/Program Files/Workspace/IO目录下新建一个文件properties.txt,并在里面输入test=0
p.setProperty("test",Integer.parseInt(p.getProperty("test"))+1+"");
if(p.getProperty("test").equals("4")){
System.out.println("你只能免费使用3次,续用请缴费");
return;
}
p.list(new PrintStream("D:/Program Files/Workspace/IO/properties.txt"));
System.out.println("程序运行了"+p.getProperty("test")+"次");
}
|
|