gpt4 book ai didi

java - 将输入流中的内容写入文件

转载 作者:行者123 更新时间:2023-12-01 17:26:26 25 4
gpt4 key购买 nike

我想将输入流写入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();
}

最佳答案

       FileWriter fstream = new FileWriter("fileName");
BufferedWriter fbw = new BufferedWriter(fstream);

while ((line = in.readLine()) != null) {

fbw.write(line + "\n");

}

关于java - 将输入流中的内容写入文件,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/14663346/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com