Results 1 to 1 of 1
Thread: Accessing a file randomly
-
Accessing a file randomly
Sometimes it is required to randomly access a file. Following code is an example where a file is randomly read.
Java Code:File file = new File("file.out"); RandomAccessFile ran = new RandomAccessFile(file, "rw"); byte ch = ran.readByte(); System.out.println("Read first character of file: " + (char)ch); // reading remaining line // Prontout text from the current cursor position System.out.println("Read full line: " + ran.readLine()); // Seek to the end of file ran.seek(file.length()); // appendind text at the end of file ran.write(0x0A); ran.writeBytes("This will complete the example"); ran.close();
Similar Threads
-
Randomly accessing files
By Java Tip in forum Java TipReplies: 0Last Post: 12-12-2007, 10:46 AM -
Randomly accessing a text file
By bugger in forum New To JavaReplies: 1Last Post: 12-07-2007, 06:20 PM


LinkBack URL
About LinkBacks
Reply With Quote
Bookmarks