I have a text file named "abcd.txt"
It contains data as "abcdefghijklmnopqrstuvwxyz"
'
So....i need to print the last byte of a file . . that is "z" after program execution'
I just tried to read file and using seek function, i tried to print...'
But...it gives error..'
Plz help me to solve this....'
Thanx in advance...'
'
Code...
'import java.io.File; import java.io.FileNotFoundException; import java.io.IOException; import java.io.RandomAccessFile; public class last_byte { public static void main(String args[]) throws FileNotFoundException, IOException { File rcfile=new File("D:/abcd.txt"); RandomAccessFile raf = new RandomAccessFile(rcfile,"rwd"); raf.seek(rcfile.length()-1); char lb=raf.readChar(); System.out.print(lb); } }
Error...
Exception in thread "main" java.io.EOFException at java.io.RandomAccessFile.readChar(RandomAccessFile.java:747) at data.last_byte.main(last_byte.java:13) Java Result: 1 BUILD SUCCESSFUL (total time: 0 seconds)