首先我喜欢..
What is simplest way to read a file into String?
String content = new Scanner(new File("H:MM-Full-AF.txt")).useDelimiter("\\Z").next();
System.out.println(content);
但后来我就像..反过来了什么?
答案 0 :(得分:0)
如果您不想使用任何其他库(如apache commons),则代码可以执行您想要的操作。但是你可能不得不试一试。
FileWriter fileWriter = null;
String content = "A string to be written to file";
File newTextFile = new File("C:\\output.txt");
fileWriter = new FileWriter(newTextFile);
fileWriter.write(content);
fileWriter.close();
这是做同样的另一种方式......
BufferedWriter out = new BufferedWriter(new FileWriter("C:\\output.txt""));
out.write("A string to be written to file");
out.close();