Advertisement
piffy

Java IO Binario

Jan 1st, 2018
478
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Java 0.97 KB | None | 0 0
  1. import java.io.*;
  2.  
  3.  
  4. public class Main {
  5.  
  6.     public static void main(String[] args) throws IOException, ClassNotFoundException {
  7.         byte b[] = {00,00,00,12};
  8.         File file = new File("Integer.dat");
  9.         FileOutputStream fos = new FileOutputStream(file);
  10.  
  11.         //YourClass object = (YourClass) ois.readObject();
  12.         ObjectOutputStream oos = new ObjectOutputStream(fos);
  13.         oos.writeInt(01);oos.writeInt(02);oos.writeObject("Ciao");
  14.         oos.write( b);
  15.         oos.flush();oos.close();
  16.         /*------------------*/
  17.         FileInputStream fis = new FileInputStream(file);
  18.         ObjectInputStream ois = new ObjectInputStream(fis);
  19.         System.out.println(ois.readInt());
  20.         System.out.println(ois.readInt());
  21.         String s = (String) ois.readObject();
  22.         System.out.println(s);
  23.         ois.read(b);
  24.         for (byte by:b)
  25.          System.out.print(by+" ");
  26.         System.out.println();
  27.         oos.close();
  28.  
  29.     }
  30. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement