//设置配置文件,使程序在运行五次后不再运行
import java.io.File;
import java.io.FileInputStream;
import java.io.FileOutputStream;
import java.util.Properties;
public class PropertiesDemo2
{
/**
* @param args
*/
public static void main(String[] args)
{
int count = 0;
Properties pro = new Properties();
FileInputStream fis = null;
FileOutputStream fos = null;
File file = new File("C:\\Users\\Administrator\\Desktop\\time.ini");
try
{
if(! file.exists())
file.createNewFile();
fis = new FileInputStream(file);
pro.load(fis);
String s = pro.getProperty("time");
if(s != null)
{
count = Integer.parseInt(s);
if(count > 5)
{
System.out.println("赶紧交钱了!");
return ;
}
}
count ++;
pro.setProperty("time", count +"");
fos = new FileOutputStream(file);
pro.store(fos, "xiugai");
} catch (Exception e)
{
e.toString();
}
finally
{
try
{
if(fis != null)
fis.close();
} catch (Exception e)
{
e.toString();
}
try
{
if(fos != null)
fos.close();
} catch (Exception e)
{
e.toString();
}
}
}
}
|
|