Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- package accesoDatos;
- import java.io.FileNotFoundException;
- import java.io.IOException;
- import java.io.RandomAccessFile;
- import javax.swing.JOptionPane;
- public class AccesoAletario1 {
- static StringBuffer sb = new StringBuffer();
- public static void main(String[] args) {
- // TODO Auto-generated method stub
- int cont = 0;
- try (RandomAccessFile fichero = new RandomAccessFile("Aleatorio", "rw");) {
- final long SIZE = fichero.length();
- char dato;
- while(cont < SIZE) {
- for (int cont1 = 0; cont1 < 40; cont1 +=2) {
- if ((dato = fichero.readChar()) == 0)
- break;
- else {
- sb.append(dato);
- }
- }
- sb.append("\n");
- cont += 40;
- fichero.seek(cont);
- }
- JOptionPane.showMessageDialog(null, sb.toString());
- } catch (FileNotFoundException e) {
- // TODO Auto-generated catch block
- e.printStackTrace();
- } catch (IOException e) {
- // TODO Auto-generated catch block
- e.printStackTrace();
- }
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement