java中如何读写文件
//读文件
public static String read(String fileName) throws IOException {
StringBuffer buffer = new StringBuffer();
BufferedReader in = new BufferedReader(new FileReader(fileName));
String s;
while( (s = in.readLine()) != null){
buffer.append(s);
buffer.append("\n");
}
in.close();
return buffer.toString();
}
//写文件
public static void write(String fileName,String text) throws IOException{
PrintWriter out = new PrintWriter(new BufferedWriter(new FileWriter(fileName)));
out.print(text);
out.close();
}