首页
学习
活动
专区
工具
TVP
发布
社区首页 >问答首页 >如何将控制台输出写入txt文件

如何将控制台输出写入txt文件
EN

Stack Overflow用户
提问于 2010-01-03 15:48:26
回答 6查看 400.2K关注 0票数 67

我尝试使用下面的代码建议(http://www.daniweb.com/forums/thread23883.html#)将控制台输出写入txt文件,但是没有成功。怎么了?

代码语言:javascript
复制
try {
      //create a buffered reader that connects to the console, we use it so we can read lines
      BufferedReader in = new BufferedReader(new InputStreamReader(System.in));

      //read a line from the console
      String lineFromInput = in.readLine();

      //create an print writer for writing to a file
      PrintWriter out = new PrintWriter(new FileWriter("output.txt"));

      //output to the file a line
      out.println(lineFromInput);

      //close the file (VERY IMPORTANT!)
      out.close();
   }
      catch(IOException e1) {
        System.out.println("Error during reading/writing");
   }
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/1994255

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档