天天看點

JAVA- IO-OutputStream

package test;

import java.io.FileOutputStream;
import java.io.IOException;

public class OutputStreamReview {

	/**
	 * 1.建立一個檔案輸出流對象
	 * 2.定義一個要輸出的字元串,将其轉化成byte數組
	 * 3.用檔案輸出流輸出
	 * 
	 */
	public static void main(String[] args) throws IOException {
		
		// FileOutputStream(File file, boolean append) 是否追加。
		FileOutputStream fos = new FileOutputStream("D:/qq/tft.txt",true);
		// getBytes():将字元串轉化成byte數組
		byte[] b = "hello~world!".getBytes();
		fos.write(b);
		fos.close();
		
	}

}