import java.io.BufferedReader;
import java.io.BufferedWriter;
import java.io.File;
import java.io.FileReader;
import java.io.FileWriter;
import java.io.IOException;
public void writeFile(String s){
try {
File file=new File("E:\\MyFile.txt");
if(!file.exists()){
file.createNewFile();
}else {
BufferedWriter writer=new BufferedWriter(new FileWriter(file));
writer.write(s);
writer.newLine();
writer.flush();
writer.close();
}
} catch (IOException e) {
e.printStackTrace();
}
}
public void readFile() throws IOException {
File file=new File("E:\\MyFile.txt");
//判断文件是否存在,不存在就创建,同时写入1,代表第一次执行
if(!file.exists()){
file.createNewFile();
BufferedWriter writer=new BufferedWriter(new FileWriter(file));
writer.write("1");
writer.newLine();
writer.flush();
writer.close();
readFile();
}else{
//如果文件存在说明不是第一次调用,然后读取文件数字,并且进行加1,然后继续写入
BufferedReader reader=new BufferedReader(new FileReader(file));
String resultNum=reader.readLine();
reader.close();
log.info("readresultNum===="+resultNum);
vars.put("order_no",resultNum);
int num=Integer.parseInt(resultNum);
num=num+1;
String s=num+"";
writeFile(s);
log.info("updates="+s);
}
}
//执行上面脚本
readFile();