我想将输入流写入java中的文件中。如何在java中将内容写入文本文件?
try {
BufferedReader in = new BufferedReader(new
InputStreamReader(client.getInputStream()));
//I want to write the content to a file line by line here
while (!in.ready()) {}
System.out.print("'\n");
in.close();
}
答案 0 :(得分:5)
FileWriter fstream = new FileWriter("fileName");
BufferedWriter fbw = new BufferedWriter(fstream);
while ((line = in.readLine()) != null) {
fbw.write(line + "\n");
}