in
public static String readText(String fileName){
StringBuilder stringBuilder=new StringBuilder();
try {
BufferedReader in = new BufferedReader(
new FileReader(
new File(fileName).getAbsoluteFile()));
try {
String s;
while ((s = in.readLine()) != null) {
stringBuilder.append(s);
stringBuilder.append('\n');
}
} finally {
in.close();
}
} catch (IOException e) {
throw new RuntimeException(e);
}
return stringBuilder.toString();
}
out
public static void writeText(String pathName,String text){
File file=new File(pathName);
try{
PrintWriter out=new PrintWriter(file.getAbsoluteFile());
try {
out.print(text);
}finally {
out.close();
System.out.println(pathName+" creating");
}
} catch (IOException e){
throw new RuntimeException(e);
}
}
优先使用Reader以防格式错误,老式的stream处理8位数据,新的可解决unicode编码。