piffy icon

Java IO Binario

piffy | PRO | 01/01/18 10:48:58 AM UTC | 0 ⭐ | 846 👁️ | Never ⏰ | []
Java |

970 B

|

None

|

0 👍

/

0 👎

import java.io.*;
 
 
public class Main {
 
    public static void main(String[] args) throws IOException, ClassNotFoundException {
        byte b[] = {00,00,00,12};
        File file = new File("Integer.dat");
        FileOutputStream fos = new FileOutputStream(file);
 
        //YourClass object = (YourClass) ois.readObject();
        ObjectOutputStream oos = new ObjectOutputStream(fos);
        oos.writeInt(01);oos.writeInt(02);oos.writeObject("Ciao");
        oos.write( b);
        oos.flush();oos.close();
        /*------------------*/
        FileInputStream fis = new FileInputStream(file);
        ObjectInputStream ois = new ObjectInputStream(fis);
        System.out.println(ois.readInt());
        System.out.println(ois.readInt());
        String s = (String) ois.readObject();
        System.out.println(s);
        ois.read(b);
        for (byte by:b)
         System.out.print(by+" ");
        System.out.println();
        oos.close();
 
    }
}

Comments