步驟:
1.創建目標對象(表示把數據存儲到哪一文件中)
2.創建文件字節輸出流對象
3.具體的輸出操作(往外寫的操作)
4.關閉資源對象
//演示文件字節輸出流
public class FileOutputStreamDemo {
public static void main(String[] args) throws IOException {
//1創建目標文件
File desFile = new File("file/des.txt");
//2創建字節輸出流對象
FileOutputStream out = new FileOutputStream(desFile);
//3IO操作
/*
* void write(int b) 將一個字節寫出到文件中
* void write(byte[] b) 將數組b中的數據寫出到文件中
* void write(byte[] b,int off,int len) 將數組中的從off索引開始的len個字節寫出到文件中
*/
//out.write(65);寫出A
out.write("哈哈哈".getBytes());
//out.write("Lucyisbeatiful".getBytes(),5,5);
//4 關閉文件
out.close();
}
}