序列化對象到磁盤上

序列化對象到磁盤上

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


public void saveObject(Object o, String filename) {  

        ObjectOutputStream out = null;  
        try {  
            out = new ObjectOutputStream(  
                    new FileOutputStream("D:/"+filename));  
  
            out.writeObject(o);  
        } catch (IOException e) {  
            throw new RuntimeException("保存文件到磁盤出錯");  
        } finally {  
            try {  
                out.close();  
            } catch (IOException e) {  
                throw new RuntimeException("關閉流出錯");  
            }  
        }  
  
    }
發佈了16 篇原創文章 · 獲贊 0 · 訪問量 2萬+
發表評論
所有評論
還沒有人評論,想成為第一個評論的人麼? 請在上方評論欄輸入並且點擊發布.
相關文章