flows streams with * .dat files

0

I'm making an application with swing and I need to link data that I enter for that application to a * .dat file. The fact is that I have three packages and each package with its * .java:

Package 1: Class Vehicles with their attributes and methods setters and getters.

Package 2: handling the file.

Package 3: Swing interface of the application.

My question is how to proceed in the flows or streams; Should I open / close one from package 2 to each of the other two packages? How do I link the packages between them?

Thank you.

    
asked by rodic 07.03.2018 в 20:18
source

1 answer

1

RandomAccessFile

This is a primitive class that implements the DataInput and DataOutput interfaces and serves to read and write data.

The construction requires a string that contains a valid path to a file or a File file. There is a second mandatory parameter called mode. The mode is a string that can contain an r (read), w (write), or both, rw. The FileNotFound exception must be captured when the constructor runs.

File f=new File("prueba.txt"); 
RandomAccessFile archivo = new RandomAccessFile( f, "rw");

The fundamental methods are:

- > seek(long pos) It allows to be placed in a specific position, counted in bytes, in the file.

What is placed is the access pointer that is the signal that marks the position to read or write.

- > long getFilePointer().Posición current of the access pointer?

- > long length() . Returns the file size.

- > readBoolean , readByte , readChar , readInt , readDouble , readFloat , readUTF , readLine .   Reading functions.

They read a data of the indicated type. In the case of readUTFlee a string in Unicode format.

? writeBoolean , writeByte , writeBytes , writeChar , writeChars writeInt , writeDouble , writeFloat , writeUTF , writeLine .

Writing functions.

All receive as a parameter, the data to write. Write above what has already been written. To write at the end you have to place the access pointer at the end of the file.

    
answered by 07.03.2018 в 20:45