We define a class in Java with his variables, setters and getters to emulate a struct in C, or a record in Pascal. In these two languages we can read/write structs from disk, in this form:
read (file, Register);
Can we do the same in Java? Y we have a class emulating a record, we have variables as data, but we have aldo methods. If we write the class on disk, are we writing the methods also? Must we write the methods for every record?
Until now I have been using a separate fields:
public static void main(String[] args) {
try(DataOutputStream out=new DataOutputStream(new FileOutputStream("C:\binaryFile.bin"));){
dos.writeInt(XCoord);
dos.writeInt(YCoord);
dos.writeUTF("Un string");
}catch(IOException e){
System.out.println("Error E/S");
}
}
pocaentropia is a new contributor to this site. Take care in asking for clarification, commenting, and answering.
Check out our Code of Conduct.