将内容写入输入流中的文件 [英] Writing the contents to a file from input stream

查看:178
本文介绍了将内容写入输入流中的文件的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我想将输入流写入java中的文件中。如何将内容写入java中的文本文件?

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();
            }


推荐答案

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

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

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

        }

这篇关于将内容写入输入流中的文件的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆