缓冲区字符流,写入内容到根目录下的hello.txt文件

时间:2023-01-21 17:59:52
import java.io.BufferedWriter;
import java.io.FileWriter;
import java.io.IOException;

/**
	缓冲区字符流,写入内容到根目录下的hello.txt文件
 */
public class BufferWriterDemo {
	public static void main(String[] args) {
		
		try {
			BufferedWriter bw=new BufferedWriter(new FileWriter("hello.txt"));
			//String str="你好\r\n你好!";
			String str="abcde";
			  for(int i=1;i<=20;i++) { 
				  
			      bw.write(str+"\t"); 
			      
			        if(i%5==0) { 
			        	//换行.....
			            bw.newLine(); 
			        }            
			    } 
			bw.close();
		} catch (IOException e) {
			e.printStackTrace();
		}
	}
}
/*
运行的在hello.txt中得:

abcde	abcde	abcde	abcde	abcde	
abcde	abcde	abcde	abcde	abcde	
abcde	abcde	abcde	abcde	abcde	
abcde	abcde	abcde	abcde	abcde

*/