(Created page with "=== Exemplo: Leitura e Escrita de Acesso Aleatório === <java5> public class LeituraEscritaAleatória { public static void main(String[] args) throws IOException { Rando...") |
|||
Line 1: | Line 1: | ||
=== Exemplo: Leitura e Escrita de Acesso Aleatório === | === Exemplo: Leitura e Escrita de Acesso Aleatório === | ||
− | < | + | <source lang="java"> |
public class LeituraEscritaAleatória { | public class LeituraEscritaAleatória { | ||
Line 23: | Line 23: | ||
} | } | ||
− | </ | + | </source> |
[[category:Ensino]] | [[category:Ensino]] |
public class LeituraEscritaAleatória {
public static void main(String[] args) throws IOException {
RandomAccessFile rf = new RandomAccessFile("raw.dat", "rw");
for(int i = 0; i < 10; i++) rf.writeDouble(i * 1.414);
rf.close();
rf = new RandomAccessFile("raw.dat", "rw");
rf.seek(5*8);
rf.writeDouble(47.0001);
rf.close();
rf = new RandomAccessFile("raw.dat", "r");
for(int i = 0; i < 10; i++)
System.out.println("Valor " + i + ": " + rf.readDouble());
rf.close();
}
}