I am trying to read data from a .dat type file using Java. This data is int string int int double. After reading this data, I want to create a class, create an object and assign the data to it, but such an error occurred in the data reading part.
public class Main {
public static void main(String[] args) {
String dosyaYolu = "test.dat";
try {
FileInputStream fis = new FileInputStream(dosyaYolu);
DataInputStream dis = new DataInputStream(fis);
while(dis.available() > 0) {
System.out.println(dis.readInt());
System.out.println(dis.readUTF());
System.out.println(dis.readInt());
System.out.println(dis.readInt());
System.out.println(dis.readDouble());
}
} catch (IOException e) {
e.printStackTrace();
}
}
}
this is the .dat file : https://drive.google.com/file/d/1F7gtkEK_Cn1a0buN8_KZo0rna2hZKS0t/view?usp=drivesdk
The error I get is like this
-1393754107
java.io.EOFException
at java.base/java.io.DataInputStream.readFully(DataInputStream.java:210)
at java.base/java.io.DataInputStream.readUTF(DataInputStream.java:594)
at java.base/java.io.DataInputStream.readUTF(DataInputStream.java:550)
at Main.main(Main.java:20)
New contributor
Furkan is a new contributor to this site. Take care in asking for clarification, commenting, and answering.
Check out our Code of Conduct.
1