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

时间:2013-02-02 15:22:17

标签: java io streaming

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

1 个答案:

答案 0 :(得分:5)

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

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

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

        }