程序运行次数练习
来源:互联网 发布:爱名网域名过户 编辑:程序博客网 时间:2024/05/16 15:49
import java.io.File;
import java.io.FileInputStream;
import java.io.FileOutputStream;
import java.io.IOException;
import java.util.Properties;
public class JiShu {
if (b)
run();
boolean isrun = true;
File configFile = new File("count.properties");
if (!configFile.exists()) {
configFile.createNewFile();
}
int count = 0; // 记录每次存储的次数
Properties prop = new Properties(); // 用于储存配置文件中的文件
FileInputStream fis = new FileInputStream(configFile);
// 把流中的数据加载到集合中
prop.load(fis);
// 获取键对应的次数
String key = "count";
// 获取键对应的次数
String value = prop.getProperty("count");
if (value != null) {
count = Integer.parseInt(value);
if (count >=5){
System.out.println("使用次数已到,请充钱!!");
isrun = false;
}
}
count++; // 使用的次数加一
prop.setProperty("count", Integer.toString(count));
// 将集合中的数据存储到配置文件中去
FileOutputStream fos = new FileOutputStream(configFile);
prop.store(fos, "");
fos.close();
fis.close();
return isrun;
}
private static void run() {
System.out.println("软件运行了!");
}
}
import java.io.FileInputStream;
import java.io.FileOutputStream;
import java.io.IOException;
import java.util.Properties;
public class JiShu {
public static void main(String[] args) throws IOException {
boolean b = checkCount();if (b)
run();
}
private static boolean checkCount() throws IOException {boolean isrun = true;
File configFile = new File("count.properties");
if (!configFile.exists()) {
configFile.createNewFile();
}
int count = 0; // 记录每次存储的次数
Properties prop = new Properties(); // 用于储存配置文件中的文件
FileInputStream fis = new FileInputStream(configFile);
// 把流中的数据加载到集合中
prop.load(fis);
// 获取键对应的次数
String key = "count";
// 获取键对应的次数
String value = prop.getProperty("count");
if (value != null) {
count = Integer.parseInt(value);
if (count >=5){
System.out.println("使用次数已到,请充钱!!");
isrun = false;
}
}
count++; // 使用的次数加一
prop.setProperty("count", Integer.toString(count));
// 将集合中的数据存储到配置文件中去
FileOutputStream fos = new FileOutputStream(configFile);
prop.store(fos, "");
fos.close();
fis.close();
return isrun;
}
private static void run() {
System.out.println("软件运行了!");
}
}
0 0
- 程序运行次数练习
- 练习:统计程序运行的次数
- 黑马程序员-学习日志-练习用于记录程序运行次数
- 实现程序运行次数计数
- 简易计算程序运行次数
- 验证程序运行次数的小程序
- Java实现程序运行次数限制
- 使用Properties记录程序运行次数
- java实现程序运行次数限定
- PAT练习-程序运行时间
- Java IO流 Properties练习-记录应用程序运行次数
- Java 判断程序运行次数---- Properties 文件计数器
- Xcode 4.6.2 运行次数为偶数程序崩溃问题
- Map系列的Properties,实现程序运行次数计数
- Xcode 4.6.2 运行次数为偶数程序崩溃问题
- 一个实用小工具(允许程序运行的次数)
- 《黑马程序员》 properties之程序运行次数限定
- 用properties写的一个程序运行次数计数的程序代码,超过次数提示注册。
- #游戏unity#AR手机游戏的平台构建
- 充分利用新款 Android 旗舰设备上更大的纵横比
- 面向对象编程与面向实例编程
- Java字节码指令列表
- 系统管理123总结
- 程序运行次数练习
- 【bzoj4883】棋盘上的守卫 题解
- gridwindowDIG
- 开发常用网站
- HTML巩固练习之网页中插入背景音乐与浮动框架
- hdu3341:Lost's revenge (AC自动机+DP)
- JAVA设计模式-适配器模式
- Shell脚本调试技术
- 用python scrapy 写东西用的小思路 Item Pipeline