Skip to content

Instantly share code, notes, and snippets.

@Cartman0
Created September 6, 2015 18:35
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save Cartman0/de33998523879591f808 to your computer and use it in GitHub Desktop.
Save Cartman0/de33998523879591f808 to your computer and use it in GitHub Desktop.
ObjectOutputStream のwriteObjectメソッドで出力されたファイルを読み込む。
/*
* To change this license header, choose License Headers in Project Properties.
* To change this template file, choose Tools | Templates
* and open the template in the editor.
*/
package objectinputoutputstreamdemo.objectinputstreamdemo;
import java.io.ObjectInputStream;
import java.io.FileInputStream;
import java.io.BufferedInputStream;
import java.io.EOFException;
/**
* ObjectInputStreamDemo
* @author nabana
* http://docs.oracle.com/javase/jp/8/api/java/io/ObjectInputStream.html
*/
public class ObjectInputStreamDemo {
public static void main(String[] args) {
// writeObjectを読み込む
try {
String file_path = "src\\objectinputoutputstreamdemo\\object_stream_file2.tmp";
System.out.println("\ninput ObjectInputStream " + file_path);
BufferedInputStream bis = new BufferedInputStream(new FileInputStream(file_path));
ObjectInputStream ois = new ObjectInputStream(bis);
Object o;
while (true) {
try {
o = ois.readObject();
System.out.println(o);
} catch (EOFException ex) {
break;
}
}
ois.close();
} catch(Exception ex) {
ex.printStackTrace();
}
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment