本帖最后由 dark_horse_xu 于 2014-10-26 00:07 编辑
import java.io.*;
import java.util.*;
public class RunCount1 {
public static void main(String[] args) {
FileInputStream fis = null;
FileOutputStream fos = null;
try {
Properties pro = new Properties();
File file = new File("haha22.properties");
if(!(file.exists()))
file.createNewFile();
fis = new FileInputStream(file);
pro.load(fis);
String value = pro.getProperty("times");
int count = 0;
if(value != null)
{
count = Integer.parseInt(value);
if (count >= 5) {
System.out.println("您好!使用次数已到,请购买!");
}
}
count++;
pro.setProperty("time",count+"");
fos = new FileOutputStream(file);
pro.store(fos,"hahahahahhahhaha");
}
catch (Exception e) {
// TODO: handle exception
throw new RuntimeException("");
}
finally
{
try {
if(fis !=null)
fis.close();
} catch (IOException e2) {
// TODO: handle exception
throw new RuntimeException("");
}
try {
if(fos !=null)
fos.close();
} catch (IOException e2) {
// TODO: handle exception
throw new RuntimeException("");
}
}
}
}
怎么配置文件里的次数不增加呢,没发现哪里有错误啊,崩溃了
|
|