List of usage examples for java.io ObjectOutputStream ObjectOutputStream
public ObjectOutputStream(OutputStream out) 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.writeFloat(1.234F);//from www. jav a2 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 { ObjectOutputStream out = new ObjectOutputStream( new BufferedOutputStream(new FileOutputStream("file.data"))); out.writeChar(100);//from w w w . ja v a 2s .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.write("java2s.com".getBytes()); out.close();/*from w w w . ja va 2s .co m*/ 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.writeLong(1111111111111L);/*from w ww. j av a 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 { float f = 1.23456f; FileOutputStream out = new FileOutputStream("test.txt"); ObjectOutputStream oout = new ObjectOutputStream(out); oout.writeFloat(f);//from w ww . ja v a2s .co m 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 { short s = 56; FileOutputStream out = new FileOutputStream("test.txt"); ObjectOutputStream oout = new ObjectOutputStream(out); // write something in the file oout.writeShort(s);/*from w w w . j av a 2 s . c o m*/ oout.writeShort(new Short("1")); 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 short System.out.println(ois.readShort()); // read and print a short System.out.println(ois.readShort()); ois.close(); }
From source file:Main.java
public static void main(String[] args) throws Exception { char b = 'F'; FileOutputStream out = new FileOutputStream("test.txt"); ObjectOutputStream oout = new ObjectOutputStream(out); // write something in the file oout.writeChar(b);// w ww . ja v a 2 s . c o m oout.writeChar('A'); 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 char System.out.println(ois.readChar()); // read and print a char System.out.println(ois.readChar()); ois.close(); }
From source file:Main.java
public static void main(String[] args) throws Exception { byte b = 12;/*from ww w . ja va 2s. co m*/ FileOutputStream out = new FileOutputStream("test.txt"); ObjectOutputStream oout = new ObjectOutputStream(out); // write something in the file oout.writeByte(b); oout.writeByte(21); 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 byte System.out.println((char) ois.readByte()); // read and print a byte System.out.println((char) ois.readByte()); ois.close(); }
From source file:Main.java
public static void main(String[] args) throws Exception { int i = 123456; FileOutputStream out = new FileOutputStream("test.txt"); ObjectOutputStream oout = new ObjectOutputStream(out); // write something in the file oout.writeInt(i);/* ww w .j a va2s . c om*/ oout.writeInt(54321); oout.flush(); oout.close(); // create an ObjectInputStream for the file we created before ObjectInputStream ois = new ObjectInputStream(new FileInputStream("test.txt")); // read and print an int System.out.println(ois.readInt()); // read and print an int System.out.println(ois.readInt()); ois.close(); }
From source file:Main.java
public static void main(String[] args) throws Exception { long l = 12345678909876L; FileOutputStream out = new FileOutputStream("test.txt"); ObjectOutputStream oout = new ObjectOutputStream(out); // write something in the file oout.writeLong(l);//from w w w . j ava 2 s .c o m oout.writeLong(987654321L); oout.flush(); oout.close(); ObjectInputStream ois = new ObjectInputStream(new FileInputStream("test.txt")); System.out.println(ois.readLine()); ois.close(); }