import java.io.IOException; import java.io.RandomAccessFile; public class RandomFile { public static void main(String[] args) throws IOException { RandomAccessFile raf = new RandomAccessFile("file.txt", "rw"); raf.write("ABCDEFGHIJKLMNOPQRSTUWXYZ".getBytes()); raf.close(); raf = new RandomAccessFile("file.txt", "rw"); raf.seek(raf.length()); raf.write("Aggiunta".getBytes()); raf.close();; byte[] bytes = new byte[28]; raf = new RandomAccessFile("file.txt", "r"); System.out.println("Byte letti: " + raf.read(bytes)); for (byte by:bytes) System.out.println((char) by); raf.seek(4); bytes = new byte[1]; System.out.println("Byte letti: " + raf.read(bytes)); for (byte by:bytes) System.out.println((char) by); raf.close(); } }