List of usage examples for java.io ObjectOutputStream close
public void close() throws IOException
From source file:Main.java
public static void main(String[] args) throws Exception { float f = 1.23456f; FileOutputStream out = new FileOutputStream("test.txt"); ObjectOutputStream oout = new ObjectOutputStream(out); oout.writeFloat(f);//from w w w.j a va 2 s .com oout.writeFloat(1234.56789f); oout.flush(); oout.close(); ObjectInputStream ois = new ObjectInputStream(new FileInputStream("test.txt")); System.out.println(ois.readFloat()); System.out.println(ois.readFloat()); ois.close(); }
From source file:Main.java
public static void main(String[] args) throws Exception { FileOutputStream out = new FileOutputStream("test.txt"); ObjectOutputStream oout = new ObjectOutputStream(out); // write something in the file oout.writeBoolean(true);// www . j av a2 s.c o m oout.flush(); oout.close(); // create an ObjectInputStream for the file we created before ObjectInputStream ois = new ObjectInputStream(new FileInputStream("test.txt")); // read and print a boolean System.out.println(ois.readBoolean()); ois.close(); }
From source file:Main.java
public static void main(String[] args) throws Exception { String s = "Hello World from java2s.com"; FileOutputStream out = new FileOutputStream("test.txt"); ObjectOutputStream oout = new ObjectOutputStream(out); // write something in the file oout.writeUnshared(s);//from w w w .j av a2s.c o m oout.flush(); oout.close(); // create an ObjectInputStream for the file we created before ObjectInputStream ois = new ObjectInputStream(new FileInputStream("test.txt")); // read and print the unshared object System.out.println(ois.readUnshared()); ois.close(); }
From source file:Main.java
public static void main(String[] args) throws Exception { ObjectOutputStream out = new ObjectOutputStream( new BufferedOutputStream(new FileOutputStream("file.data"))); out.writeByte(1);/*from w w w . ja va 2 s.com*/ out.close(); ObjectInputStream in = new ObjectInputStream(new BufferedInputStream(new FileInputStream("file.data"))); byte[] byteArray = new byte[10]; in.read(byteArray); System.out.println(Arrays.toString(byteArray)); in.close(); }
From source file:Main.java
public static void main(String[] args) throws Exception { ObjectOutputStream out = new ObjectOutputStream( new BufferedOutputStream(new FileOutputStream("file.data"))); out.writeShort(1);/*from w w w . j a v a 2s . c o m*/ out.close(); ObjectInputStream in = new ObjectInputStream(new BufferedInputStream(new FileInputStream("file.data"))); byte[] byteArray = new byte[10]; in.read(byteArray); System.out.println(Arrays.toString(byteArray)); in.close(); }
From source file:Main.java
public static void main(String[] args) throws Exception { String s = "Hello World from java2s.com"; FileOutputStream out = new FileOutputStream("test.txt"); ObjectOutputStream oout = new ObjectOutputStream(out); // write something in the file oout.writeUTF(s);/*w w w . ja va 2s . com*/ oout.flush(); oout.close(); // create an ObjectInputStream for the file we created before ObjectInputStream ois = new ObjectInputStream(new FileInputStream("test.txt")); // read and print the whole content byte[] b = new byte[13]; ois.readFully(b); String array = new String(b); System.out.println(array); ois.close(); }
From source file:Main.java
public static void main(String[] args) throws Exception { ObjectOutputStream out = new ObjectOutputStream( new BufferedOutputStream(new FileOutputStream("file.data"))); out.writeChar(100);// w w w .j a va2s . c o m out.close(); ObjectInputStream in = new ObjectInputStream(new BufferedInputStream(new FileInputStream("file.data"))); byte[] byteArray = new byte[10]; in.read(byteArray); System.out.println(Arrays.toString(byteArray)); in.close(); }
From source file:Main.java
public static void main(String[] args) throws Exception { FileOutputStream out = new FileOutputStream("test.txt"); ObjectOutputStream oout = new ObjectOutputStream(out); oout.writeObject(new Example()); oout.flush();/*from w w w . ja v a2s . c o m*/ oout.close(); ObjectInputStream ois = new ObjectInputStream(new FileInputStream("test.txt")); Example a = (Example) ois.readObject(); System.out.println(a.isDefault); System.out.println(a.string); ois.close(); }
From source file:Main.java
public static void main(String[] args) throws Exception { String s = "Hello World from java2s.com"; FileOutputStream out = new FileOutputStream("test.txt"); ObjectOutputStream oout = new ObjectOutputStream(out); // write something in the file oout.writeUTF(s);/*from w ww . ja va 2s .c om*/ oout.flush(); oout.close(); // create an ObjectInputStream for the file we created before ObjectInputStream ois = new ObjectInputStream(new FileInputStream("test.txt")); // read and print from index 0 to 7 byte[] b = new byte[13]; ois.readFully(b, 0, 7); String array = new String(b); System.out.println(array); ois.close(); }
From source file:A.java
public static void main(String[] args) throws IOException, ClassNotFoundException { A b1 = new A(); B b2 = new B(); ObjectOutputStream o = new ObjectOutputStream(new FileOutputStream("File.out")); o.writeObject(b1);/*from w w w . j a v a 2 s. com*/ o.writeObject(b2); o.close(); ObjectInputStream in = new ObjectInputStream(new FileInputStream("File.out")); b1 = (A) in.readObject(); }