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();
}
}
}
執行代碼如下(這裡沒輸出,實質上已經發生變化):

沒執行代碼之前:
執行代碼之後: