1.写入文件
private static void writeFile(String s,String filePath){
FileWriter writer;
try {
writer = new FileWriter(filePath);
writer.write("");
writer.write(s);
writer.flush();
writer.close();
} catch (IOException e) {
e.printStackTrace();
}
}
2.读取文件
public static String getTextFileContent(File file) throws IOException {
StringBuilder stringBuilder = new StringBuilder();
BufferedReader br = new BufferedReader(new InputStreamReader(new FileInputStream(file), "utf-8"));
String temp;
while ((temp = br.readLine()) != null) {
stringBuilder.append(temp);
}
br.close();
return stringBuilder.toString();
}