📄 loadandsave.java
字号:
package model;
import java.awt.Point;
import java.io.BufferedReader;
import java.io.File;
import java.io.FileInputStream;
import java.io.FileNotFoundException;
import java.io.FileOutputStream;
import java.io.InputStreamReader;
import java.io.PrintWriter;
import java.util.Date;
import java.util.Properties;
public class LoadAndSave {
private static final Properties prop=new Properties();
public static File recordFile=new File("record.dat");
public static File setFile=new File("setup.ini");
public static StringBuilder[] setLines;
public static int getRecord(int total) {
int seconds=999999999;
try {
BufferedReader bReader=new BufferedReader(new InputStreamReader(new FileInputStream(recordFile)));
String line=null;
while((line=bReader.readLine())!=null)
try {
String[] values=line.split("\t");
int n=Integer.parseInt(values[1]);
int s=Integer.parseInt(values[2]);
if(n==total&&s<seconds) seconds=s;
} catch (RuntimeException e) {
}
bReader.close();
} catch (Exception e) {
}
return seconds;
}
public static void load(){
try {
prop.loadFromXML(new FileInputStream(setFile));
} catch (Exception e) {
}
}
public static int loadLevel() {
int level=0;
load();
try {
level=Integer.parseInt(prop.getProperty("level"));
} catch (NumberFormatException e) {
}
return level;
}
public static Point loadLocation() {
Point location=null;
load();
int x=0;
int y=0;
try {
x = Integer.parseInt(prop.getProperty("frameX"));
y = Integer.parseInt(prop.getProperty("frameY"));
} catch (NumberFormatException e) {
}
location=new Point(x,y);
return location;
}
public static void save(){
try {
prop.storeToXML(new FileOutputStream(setFile), "no comment");
} catch (Exception e) {
}
}
public static void saveLevel(int level){
prop.setProperty("level", level+"");
save();
}
public static void saveLocation(Point p) {
prop.setProperty("frameX", p.x+"");
prop.setProperty("frameY", p.y+"");
save();
}
public static void saveRecord(int total, int seconds) {
try {
FileOutputStream fos=new FileOutputStream(recordFile,true);
PrintWriter out=new PrintWriter(fos,true);
out.println(new Date(System.currentTimeMillis())+"\t"+total+"\t"+seconds);
out.close();
} catch (FileNotFoundException e) {
}
}
}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -