-------
android培训、
java培训、期待与您交流! ----------/*
用于记录应用程序运行次数。
如果使用次数已到,那么给出注册提示。
很容易想到的是:计数器。
可是该计数器定义在程序中,随着程序的运行而在内存中存在,并进行自增。
可是随着该应用程序的退出,该计数器也在内存中消失了。
下一次在启动该程序,又重新开始从0计数。
这样不是我们想要的。
程序即使结束,该计数器的值也存在。
下次程序启动会先加载该计数器的值并加1后再重新存储起来。
所以要建立一个配置文件,用于记录该软件的使用次数。
该配置文件使用键值对的形式。
这样便于阅读数据,并操作数据。
键值对数据是Map集合。
数据是以文件形式存储,使用IO技术,、
那么map+io--->Properties
配置文件可以实现应用程序数据的共享
*/
import java.io.*;
import java.util.*;
class RunCount
{
public static void main(String[] args)throws IOException
{
Properties prop = new Properties();
File file = new File("count.ini");//封装了,可以对文件进行判断
if(!file.exists())
file.createNewFile();
FileInputStream fis = new FileInputStream(file);//("count.properties");
prop.load(fis);
int count = 0;
String value = prop.getProperty("time");//第一次时,为null
if(value!=null)
{
count = Integer.parseInt(value);
if(count>=5)
{
System.out.println("nihao,使用次数已到,拿钱!");
return ;
}
}
count++;
prop.setProperty("time",count+"");
FileOutputStream fos = new FileOutputStream(file);
prop.store(fos,"");
fos.close();
fis.close();
}
}
/*
键值对
name = zhangsan
age=20
多的话,xml方便
<persons>
<person id="001">
<name>zs<//name>
</person>
<person id="001">
</person>
</persons>
更简单的“
dom4j dom for java four for----four
*/------- android培训、 java培训、期待与您交流! ----------
用于记录应用程序运行次数。
如果使用次数已到,那么给出注册提示。
很容易想到的是:计数器。
可是该计数器定义在程序中,随着程序的运行而在内存中存在,并进行自增。
可是随着该应用程序的退出,该计数器也在内存中消失了。
下一次在启动该程序,又重新开始从0计数。
这样不是我们想要的。
程序即使结束,该计数器的值也存在。
下次程序启动会先加载该计数器的值并加1后再重新存储起来。
所以要建立一个配置文件,用于记录该软件的使用次数。
该配置文件使用键值对的形式。
这样便于阅读数据,并操作数据。
键值对数据是Map集合。
数据是以文件形式存储,使用IO技术,、
那么map+io--->Properties
配置文件可以实现应用程序数据的共享
*/
import java.io.*;
import java.util.*;
class RunCount
{
public static void main(String[] args)throws IOException
{
Properties prop = new Properties();
File file = new File("count.ini");//封装了,可以对文件进行判断
if(!file.exists())
file.createNewFile();
FileInputStream fis = new FileInputStream(file);//("count.properties");
prop.load(fis);
int count = 0;
String value = prop.getProperty("time");//第一次时,为null
if(value!=null)
{
count = Integer.parseInt(value);
if(count>=5)
{
System.out.println("nihao,使用次数已到,拿钱!");
return ;
}
}
count++;
prop.setProperty("time",count+"");
FileOutputStream fos = new FileOutputStream(file);
prop.store(fos,"");
fos.close();
fis.close();
}
}
/*
键值对
name = zhangsan
age=20
多的话,xml方便
<persons>
<person id="001">
<name>zs<//name>
</person>
<person id="001">
</person>
</persons>
更简单的“
dom4j dom for java four for----four
*/------- android培训、 java培训、期待与您交流! ----------