My problem is when I get the data from a text file it seems to be in the wrong encoding or somthing. I dont know how to get around this issue sorry. Thanks in advance. Here is the code.
private static String readLogFile(String path, File f) throws IOException {
if (f.exists()){
String data;
try (RandomAccessFile raf = new RandomAccessFile(f, "rw")) {
char ch = raf.readChar();
raf.seek(f.length());
String dataCh = String.valueOf(ch);
data = dataCh.toString();
System.out.println(data);
}
return data;
}
else{
String data = "";
return data;
}
}
From the Java Docs
Note, “two bytes are read”
Because Java supports Unicode character’s the stream is automatically assuming that reading a character from the stream needs to produce a Unicode character.
Try
char ch = (char)raf.readByte();instead