1. 程式人生 > >【FileOutputStream類:寫出內容到檔案】

【FileOutputStream類:寫出內容到檔案】

package test;

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

/**
 * @author shusheng
 * @description
 * @Email [email protected]
 * @date 2018/11/9 14:50
 */
public class FileOutputStreamDemo1 {

    public static void main(String[] args) throws IOException {
        /**
         * 建立位元組輸出流物件
         *建立位元組輸出流物件了做了幾件事情:
         *A:呼叫系統功能去建立檔案
         *B:建立 fos 物件
         *C:把 fos 物件指向這個檔案
         
*/ FileOutputStream fos = new FileOutputStream("fos.txt"); /**寫資料*/ fos.write("Hello,shusheng".getBytes()); fos.write("java".getBytes()); /**釋放資源,關閉此檔案輸出流, * 並釋放與此流有關的所有系統資源*/ fos.close(); } }