今天看到Properties的用法,觉得很有意思,因为很多共享文件的使用次数限制就是通过这样的方法实现的。我们只要找到这个次数限制文件就可以破解了。
程序清单: PropertiesFile.java
import java.util.*;
import java.io.*;

class PropetiesFile
...{
public static void main(String[] args)
...{
Properties settings = new Properties(); //实例化一个对象。
try
...{
settings.load(new FileInputStream("d:/java/Count.txt"));
}
catch(Exception e)
...{
settings.setProperty("Count",new Integer(0).toString());
}
int c = Integer.parseInt(settings.getProperty("Count")) + 1;
System.out.println("这是本程序第"+c+"次使用!");
settings.put("Count",new Integer(c).toString());
try
...{
settings.store(new FileOutputStream("d:/java/Count.txt"),"该程序已经使用过了");
}
catch(Exception e)
...{
System.out.println(e.getMessage());
}
while(c >= 5)
...{
System.out.println("这是你最后一次使用本程序!");
return;
}
}
}
本文介绍了一个简单的Java程序,利用Properties类记录程序运行次数,并在达到设定阈值时限制使用。程序通过读取和写入本地文件来跟踪使用次数。

被折叠的 条评论
为什么被折叠?



