Writing the contents to a file from input stream

荒凉一梦 提交于 2019-12-23 04:33:58

问题


I want to write the inputstream into a file in java. How to write the contents into a text file in 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:


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

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

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

        }


来源:https://stackoverflow.com/questions/14663346/writing-the-contents-to-a-file-from-input-stream

标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!