有些软件有版权,软件有使用次数限制,而让你购买权限,如下方法设置使用次数
用ProPerties类对象去存读取硬盘中的数据,然后去操作这个和对象属性
先创建一个File的路径,然后用用FileInputstream的对象去读取File路径的内容 让后再用ProPerties类对象再去读取FileInputStream的对象
再用ProPerties类对象去调一个获取 value值的方法在修改其值,
先读取是因为你要改变这个存储内容,如果你是写入+读取那么写入和读取一直循环;而如果是先读取+写入 这你可以写入时改变内
容而读取时会读取不一样的内容
具体人如下
package Demo;
import java.io.File;
import java.io.FileInputStream;
import java.io.FileOutputStream;
import java.io.IOException;
import java.util.Properties;
//>>>>>>>>>>>>>>>>>>>>>>> 应用软件次数 <<<<<<<<<<<<<<<<<<<<<<<<<<<
public class Demo1 {
public static void main(String [] args)throws IOException{
File file =new File("C:\\Users\\廖元辉\\Desktop\\12月20日线程一\\应用软件次数.txt");
if(!file.exists()){
file.createNewFile(); //找到一个目录记录使用次数,如果这个文件不存在就创建一个
}
Properties p=new Properties();
FileInputStream intput =new FileInputStream(file); //读取文件的内容
p.load(intput); //放入到集合中去
FileOutputStream output=new FileOutputStream(file);
String value=p.getProperty("count"); //取出对应的value值.......一下代码就不解释了 哈哈
int count=0;
if(value!=null){
count=Integer.parseInt(value)
}
System.out.println("....");
count++;
if(count>=3){
System.out.println("你的使用到了次"+count+"请缴费使用");
}else{
System.out.println("你的使用到了"+count +"软件");
}
p.setProperty("count",count+"");
p.store(output, "hehe");
}
}