天天看點

輸出流OutputStream

public class OutputStreamDemo {

	public static void main(String[] args) throws IOException {
		String str = "把現在寫的内容複制到J:/Java安裝包/20190401/OutputStreamDemo.txt裡面";
		try {
			//建立一個輸出流
			 OutputStream OPS= new FileOutputStream("J:/Java課程資料/20190401/OutputStreamDemo.txt");
			 //将str的byte數組資料寫入到輸出流
			 OPS.write(str.getBytes());
			 OPS.flush();
			 OPS.close();
			 
			
		} catch (FileNotFoundException e) {
			// TODO: handle exception
			e.printStackTrace();
		}
	}
}
           

執行代碼如下(這裡沒輸出,實質上已經發生變化):

輸出流OutputStream

沒執行代碼之前:

輸出流OutputStream

執行代碼之後:

輸出流OutputStream
輸出流OutputStream