Advertisement
Sie7e

leer registros de 40bytes

Nov 12th, 2012
111
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Java 1.24 KB | None | 0 0
  1. package accesoDatos;
  2.  
  3. import java.io.FileNotFoundException;
  4. import java.io.IOException;
  5. import java.io.RandomAccessFile;
  6.  
  7. import javax.swing.JOptionPane;
  8.  
  9. public class AccesoAletario1 {
  10.     static StringBuffer sb = new StringBuffer();
  11.  
  12.     public static void main(String[] args) {
  13.         // TODO Auto-generated method stub
  14.         int cont = 0;
  15.         try (RandomAccessFile fichero = new RandomAccessFile("Aleatorio", "rw");) {
  16.             final long SIZE = fichero.length();
  17.             char dato;
  18.             while(cont < SIZE) {
  19.                 for (int cont1 = 0; cont1 < 40; cont1 +=2) {
  20.                     if ((dato = fichero.readChar()) == 0)
  21.                         break;
  22.                     else {
  23.                         sb.append(dato);
  24.                     }
  25.                 }
  26.                 sb.append("\n");
  27.                 cont += 40;
  28.                 fichero.seek(cont);
  29.             }
  30.             JOptionPane.showMessageDialog(null, sb.toString());
  31.         } catch (FileNotFoundException e) {
  32.             // TODO Auto-generated catch block
  33.             e.printStackTrace();
  34.         } catch (IOException e) {
  35.             // TODO Auto-generated catch block
  36.             e.printStackTrace();
  37.         }
  38.     }
  39.  
  40. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement