system.out.println() 的结果写入文件中,换行
package com.test;import java.io.File;import java.io.FileOutputStream;import java.io.IOException;import java.io.OutputStream;import java.text.SimpleDateFormat;import java.util.ArrayList;import java.util.Date;import java.util.List;public class TestBreakStream {/** * @param args * @throws IOException */public static void main(String[] args) throws IOException {List<String> nums = new ArrayList<String>();for(int i=0 ;i<200;i++){nums.add(i+"");}//make dir and make fileSimpleDateFormat format = new SimpleDateFormat("yyyyMMddhhmmss");String now = format.format(new Date());String fileUrl = "f:\\success\\";String fileName = fileUrl+now+".txt";//write into file with breaklineFile file = new File(fileUrl);OutputStream os =null;if(file.exists()){os = new FileOutputStream(fileName);}else{file.mkdirs();os = new FileOutputStream(fileName);}for(int i = 0;i<nums.size();i++){String num = i+"、"+nums.get(i)+"\r\n";os.write(num.getBytes());}os.flush();os.close();System.out.println("success write out");}}