62,614
社区成员
发帖
与我相关
我的任务
分享
public static String readFile(String path)
{
String str = "";
File file = new File(path);
BufferedReader reader = null;
try {
reader = new BufferedReader(new FileReader(file));
String tempString = null;
String br= System.getProperty("line.separator");
while ((tempString = reader.readLine()) != null) {
// 这里可以去判断下楼主自己写
//............
str = str+ tempString+br;
}
reader.close();
} catch (IOException e) {
e.printStackTrace();
} finally {
if (reader != null) {
try {
reader.close();
} catch (IOException e1) {
}
}
}
return str;
}
public static void writeToFile(String filePath, String sets) throws IOException {
FileWriter fw = new FileWriter(filePath);
PrintWriter out = new PrintWriter(fw);
out.write(sets);
out.println();
fw.close();
out.close();
}