File operation




















This operation is the common operation performed on the file. Once the file is created, it must be opened before performing the file processing operations. When the user wants to open a file, it provides a file name to open the particular file in the file system. It tells the operating system to invoke the open system call and passes the file name to the file system. This operation is used to write the information into a file. A system call write is issued that specifies the name of the file and the length of the data has to be written to the file.

Whenever the file length is increased by specified value and the file pointer is repositioned after the last byte written. This operation reads the contents from a file. A Read pointer is maintained by the OS, pointing to the position up to which the data has been read. The seek system call re-positions the file pointers from the current position to a specific place in the file i. This operation is generally performed with those file management systems that support direct access files.

Deleting the file will not only delete all the data stored inside the file it is also used so that disk space occupied by it is freed. In order to delete the specified file the directory is searched. When the directory entry is located, all the associated file space and the directory entry is released.

Truncating is simply deleting the file except deleting attributes. The file is not completely deleted although the information stored inside the file gets replaced. When the processing of the file is complete, it should be closed so that all the changes made permanent and all the resources occupied should be released. On closing it deallocates all the internal descriptors that were created when the file was opened.

The Files those are created by the System. All the System Files are Stored into the System by using. Files are not made for just reading the Contents, we can also Perform Some other operations on the Files those are Explained below As :. We can Also Link a File with any other File. Dinesh Thakur is a Freelance Writer who helps different clients from all over the globe.

The following code shows how this might look:. For more information, see The try-with-resources Statement. If your code has opened any streams or channels, you should close them in a finally block.

The previous example would look something like the following using the try-catch-finally approach:. For more information, see Catching and Handling Exceptions. This class has some useful methods that return the file involved getFile , the detailed message string getMessage , the reason why the file system operation failed getReason , and the "other" file involved, if any getOtherFile. Several Files methods accept an arbitrary number of arguments when flags are specified.

For example, in the following method signature, the ellipses notation after the CopyOption argument indicates that the method accepts a variable number of arguments, or varargs , as they are typically called:. When a method accepts a varargs argument, you can pass it a comma-separated list of values or an array CopyOption[] of values. For random access files, a method is needed just to specify from where to take the data.

Therefore, the file seek operation performs this task.



0コメント

  • 1000 / 1000