Created
September 6, 2015 18:35
-
-
Save Cartman0/de33998523879591f808 to your computer and use it in GitHub Desktop.
ObjectOutputStream のwriteObjectメソッドで出力されたファイルを読み込む。
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
/* | |
* 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