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 { byte b = 127; FileOutputStream out = new FileOutputStream("test.txt"); ObjectOutputStream oout = new ObjectOutputStream(out); // write something in the file oout.writeByte(b);/*from w ww.j a va 2 s . co 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.readUnsignedByte()); ois.close(); }
From source file:Main.java
public static void main(String[] args) throws Exception { short b = 32767; FileOutputStream out = new FileOutputStream("test.txt"); ObjectOutputStream oout = new ObjectOutputStream(out); // write something in the file oout.writeShort(b);// w ww.j a v a2s. co 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 short System.out.println(ois.readUnsignedShort()); 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(), 1, 2); out.close();/* w ww .j av a 2s. c om*/ 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.writeChars("java2s.com"); out.close();/* w ww .j a va2s . com*/ 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.writeDouble(1.234);/*from www . j a v 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 { ObjectOutputStream out = new ObjectOutputStream( new BufferedOutputStream(new FileOutputStream("file.data"))); out.write(1);/* ww w . j av a2 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.writeShort(1);//from w w w .j a v a 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 { ObjectOutputStream out = new ObjectOutputStream( new BufferedOutputStream(new FileOutputStream("file.data"))); out.writeBoolean(true);//from w w w .j a 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.writeBytes("java2s.com"); out.close();//from w ww. java 2 s. com 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.writeByte(1);//from w w w . j a v a2 s .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(); }