Properties继承自Hashtable,使用键值对存储数据,便于进行数据管理。下面是一个模拟游戏数据存储的例子。
import java.io.File;
import java.io.FileReader;
import java.io.FileWriter;
import java.io.IOException;
import java.util.Properties;
public class Test {
private static final String PATH = "C:\\Users\\student\\Desktop";
public static void main(String[] args) throws IOException{
Properties prop = new Properties();
int newScore = 10;//当前得分
String difficulty = "Easy";//当前游戏难度
//首先判断文件是否存在
if(new File(PATH,"test.properties").exists()){
//载入文件
prop.load(new FileReader(new File(PATH,"test.properties")));
//判断本次游戏难度
if(difficulty == "Easy"){
//判断是否超过历史分数
if(Integer.parseInt(prop.getProperty("easy_score")) < newScore){
prop.setProperty("easy_score", newScore+"");//更改存储数据
pro
2万+




被折叠的 条评论
为什么被折叠?



