DEV Community

221910302029
221910302029

Posted on

File management in java

File management in java
In this tutorial you will learn about java Programming - File management in java, File operation functions in java, Defining and opening a file, Closing a file, The getw and putw functions, The fprintf & fscanf functions, Random access to files and fseek function.C supports a number of functions that have the ability to perform basic file operations, which include:1. Naming a file2. Opening a file3. Reading from a file4. Writing data into a file5. Closing a file
•Real life situations involve large volume of data and in such cases, the console oriented I/O operations pose two major problems
•It becomes cumbersome and time consuming to handle large volumes of data through terminals.
•The entire data is lost when either the program is terminated or computer is turned off therefore it is necessary to have more flexible approach where data can be stored on thedisks and read whenever necessary, without destroying the data. This method employs the concept of files to store data.

File operation functions in java:
WRITE – Opens the file for write access.
APPEND – Appends the new data to the end of the file. This option is used with the WRITE or CREATE options.
TRUNCATE_EXISTING – Truncates the file to zero bytes. This option is used with the WRITE option.
CREATE_NEW – Creates a new file and throws an exception if the file already exists.
CREATE – Opens the file if it exists or creates a new file if it does not.
DELETE_ON_CLOSE – Deletes the file when the stream is closed. This option is useful for temporary files.
SPARSE – Hints that a newly created file will be sparse. This advanced option is honored on some file systems, such as NTFS, where large files with data "gaps" can be stored in a more efficient manner where those empty gaps do not consume disk space.
SYNC – Keeps the file (both content and metadata) synchronized with the underlying storage device.
DSYNC – Keeps the file content synchronized with the underlying storage device.

Top comments (0)