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 { ObjectOutputStream out = new ObjectOutputStream( new BufferedOutputStream(new FileOutputStream("file.data"))); out.writeDouble(1.234);/*from www . ja v a 2s .c om*/ 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.writeBoolean(true);//from w ww. ja va 2 s .co 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 { ObjectOutputStream out = new ObjectOutputStream( new BufferedOutputStream(new FileOutputStream("file.data"))); out.writeFloat(1.234F);/*from www . jav a 2s .c om*/ 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);/*from ww w . j a v a 2 s. co m*/ oout.flush(); oout.close(); // create an ObjectInputStream for the file we created before Main ois = new Main(new FileInputStream("test.txt")); // read and print an object and cast it as string System.out.println((String) ois.readUTF()); // get the class for string and print the name ObjectStreamClass streamClass = ObjectStreamClass.lookup(Integer.class); System.out.println(ois.resolveClass(streamClass).getName()); 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.writeChars("java2s.com"); out.close(); ObjectInputStream in = new ObjectInputStream(new BufferedInputStream(new FileInputStream("file.data"))); byte[] byteArray = new byte[10]; in.read(byteArray);// www . j a va 2s . c om 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.writeBytes("java2s.com"); out.close(); ObjectInputStream in = new ObjectInputStream(new BufferedInputStream(new FileInputStream("file.data"))); byte[] byteArray = new byte[10]; in.read(byteArray);/*from w ww .j ava 2 s . com*/ 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.writeLong(1111111111111L);//from www . java 2 s.c om 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); oout.writeUTF(s);// www .ja v a 2 s. c o m oout.writeUTF("This is an example from java2s.com"); oout.flush(); oout.close(); ObjectInputStream ois = new ObjectInputStream(new FileInputStream("test.txt")); System.out.println(ois.readUTF()); System.out.println(ois.readUTF()); 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.write("java2s.com".getBytes()); out.close(); ObjectInputStream in = new ObjectInputStream(new BufferedInputStream(new FileInputStream("file.data"))); byte[] byteArray = new byte[10]; in.read(byteArray);// w w w .j a v a 2 s . com 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!"; FileOutputStream out = new FileOutputStream("test.txt"); ObjectOutputStream oout = new ObjectOutputStream(out); oout.writeUTF(s);/* ww w.j a va 2 s. c om*/ oout.writeUTF("This is an example from java2s.com"); oout.flush(); oout.close(); ObjectInputStream ois = new ObjectInputStream(new FileInputStream("test.txt")); ois.skipBytes(4); for (int i = 0; i < ois.available() - 4; i++) { System.out.print((char) ois.readByte()); } ois.close(); }