RandomAccessFiles in Java
import java.io.File;
import java.io.RandomAccessFile;
import java.io.IOException;
public class RandomAccessFileExample {
private static void doAccess() {
try {
File file = new File("Test5Example.txt");
RandomAccessFile raf = new RandomAccessFile(file, "rw");
// Read a character
byte ch = raf.readByte();
System.out.println("Read first character of file: " + (char)ch);
System.out.println("Read full line: " + raf.readLine());
// Seek to the end of file
raf.seek(file.length());
// Append to the end of the file
raf.writeChars("for appending to the input file");
raf.writeBytes("this will also written into the output file");
raf.close();
}
catch (IOException e) {
System.out.println("IOException");
e.printStackTrace();
}
}
public static void main(String[] args) {
doAccess();
}
import java.io.RandomAccessFile;
import java.io.IOException;
public class RandomAccessFileExample {
private static void doAccess() {
try {
File file = new File("Test5Example.txt");
RandomAccessFile raf = new RandomAccessFile(file, "rw");
// Read a character
byte ch = raf.readByte();
System.out.println("Read first character of file: " + (char)ch);
System.out.println("Read full line: " + raf.readLine());
// Seek to the end of file
raf.seek(file.length());
// Append to the end of the file
raf.writeChars("for appending to the input file");
raf.writeBytes("this will also written into the output file");
raf.close();
}
catch (IOException e) {
System.out.println("IOException");
e.printStackTrace();
}
}
public static void main(String[] args) {
doAccess();
}
Hi Phanindra..
u were in IBM?
in past
Posted by SANTHOSH | 9:24 PM
Hi Phanindra..
u were in IBM?
in past
Posted by SANTHOSH | 9:25 PM