java流

code小生 2014-09-25 05:52:34
如何利用输出流向txt文件中输入多行数据?
...全文
207 6 打赏 收藏 转发到动态 举报
写回复
用AI写文章
6 条回复
切换为时间正序
请发表友善的回复…
发表回复
code小生 2014-10-06
  • 打赏
  • 举报
回复
多谢多谢,解决了。初学java,望指教。
2.wa 2014-09-27
  • 打赏
  • 举报
回复
下载 apache 或者 Google 的 common 包。

现成的工具包。省去大量代码

姜小白- 2014-09-26
  • 打赏
  • 举报
回复

 // 指定输出文件
PrintStream ps = new PrintStream(new File("d:\\out.txt"));
// 将指定的输出赋给系统输出
System.setOut(ps);
int i = 0;
while (i < 100) {
	System.out.println(i + " " + UUID.randomUUID().toString());
	i++;
}
System.out.flush();
System.out.close();
可以通过println,也可以通过 "\r\n" 来换行

while (i < 100) {
	System.out.print(i + " " + UUID.randomUUID().toString() + "\r\n");
	i++;
}
code小生 2014-09-26
  • 打赏
  • 举报
回复
两行的的输入已经实现了,问题就是多行的输入问题。
aaron_gzt 2014-09-26
  • 打赏
  • 举报
回复
可以在输入内容中用\r\n来实现回车换行
姜小白- 2014-09-25
  • 打赏
  • 举报
回复

// 指定输出文件
PrintStream ps = new PrintStream(new File("d:\\out.txt"));
// 将指定的输出赋给系统输出
System.setOut(ps);
System.out.println("123");
System.out.println("345");
System.out.flush();
System.out.close();
代码仅供参考

50,547

社区成员

发帖
与我相关
我的任务
社区描述
Java相关技术讨论
javaspring bootspring cloud 技术论坛(原bbs)
社区管理员
  • Java相关社区
  • 小虚竹
  • 谙忆
加入社区
  • 近7日
  • 近30日
  • 至今
社区公告
暂无公告

试试用AI创作助手写篇文章吧