java 打印流,输入内容到文件中

package com.wowowo.io5;

import java.io.File;
import java.io.FileNotFoundException;
import java.io.PrintWriter;

public class TestPrintWriter {
    
    

	/**
	 * @param args
	 */
	public static void main(String[] args) {
    
    
		// TODO Auto-generated method stub

		//打印流
		
		/*
		 *  PrintStream :针对字节 调用println 内容中有换行符等   自动调用flush方法(自动发送缓冲区的内容到文件中)  
		 *  PrintWriter:针对字符   只有在调用println 才会 自动调用flush方法(自动发送缓冲区的内容到文件中)
		 */		
		
		//System.out.println()  打印到屏幕(标准输出设备)  建立在 PrintStream基础上
		File file=new File("d:/aa/1.txt");
		
		try {
    
    
			
			PrintWriter printWriter=new PrintWriter(file);
			
			
			printWriter.println("hello");
			
			printWriter.println("world");
			
			printWriter.close();
			
			
			
		} catch (FileNotFoundException e) {
    
    
			// TODO Auto-generated catch block
			e.printStackTrace();
		}
		
		
		
		
	}

}

猜你喜欢

转载自blog.csdn.net/Rockandrollman/article/details/130394562