Advertisement
cardel

Ejemplo proyecto Java

Jun 29th, 2023
799
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Java 0.89 KB | None | 0 0
  1. import java.io.File;
  2. import java.io.FileInputStream;
  3. import java.io.FileOutputStream;
  4. import java.io.IOException;
  5. import java.util.Arrays;
  6.  
  7. class Main {
  8.     //Guardar
  9.   public static void main(String[] args) {
  10.     byte data[] = {1,1,1,0,0,0,1,0,0,0,1,1,1,1,1,0,0,0,0,1,0,1,0,0,1,0,0,1,0,0,0,1,00,0,0,1,0,1,0,1,1,1,1,0,0,1,1,1,0,1,1,1,1,0,0,1};
  11.         System.out.println(Arrays.toString(data));
  12.        
  13.  
  14.         try {  
  15.             FileOutputStream fos = new FileOutputStream("salida.bin");
  16.             fos.write(data);
  17.             fos.close();
  18.         }
  19.         catch(IOException e) {
  20.             e.getStackTrace();
  21.         }
  22.  
  23.         //Leer
  24.         try{
  25.             File fin = new File("salida.bin");
  26.             FileInputStream finstream = new FileInputStream(fin);
  27.             byte[] dataIn = new byte[(int) fin.length()];
  28.             finstream.read(dataIn);
  29.             finstream.close();
  30.             System.out.println(Arrays.toString(dataIn));
  31.  
  32.         }
  33.         catch(IOException e) {
  34.             e.getStackTrace();
  35.         }
  36.   }
  37. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement