Need to write a program that removes the last character of a file only if it's not an int / number. This what I have so far.
import java.io.*;
public class RemoveTurn{
public static void main(String[] arg){
try{
RandomAccessFile raf = new RandomAccessFile("test.txt", "rw");
long length = raf.length();
System.out.println("File Length="+raf.length());
//supposing that last line is of 8
raf.setLength(length - 1);
System.out.println("File Length="+raf.length());
raf.close();
}catch(Exception ex){
ex.printStackTrace();
}
}
}
Program skeleton was taken from: happycodings.com
the simple idea is
I definitely recommend you using apahe common IO, your life will become very easy.
sample code:
EDIT:
You don't need to use Common IO, there are many other ways of
reading from
andwriting to
a file in java