Home MS Office File Handling in Java Tutorial in Urdu

File Handling in Java Tutorial in Urdu


File Handling in Java which is use to write, delete, and search, make etc files and folders with the help of programming. There are many benefits to using file handling such as get data with a user and save with file or folder or any users search any data, you can easily display files on your computer with the help of file handling.

Below, I shared complete guide File Handling in Java with explains and the short description, you must be read and understand, However, I have made a video tutorial on this topic, I have included on below post, If you face any problem to understand, I prefer to watch the video tutorial. I already shared helpful knowledge about java:


Stream Classes in Java

Java works with streams of data.  A stream is a sequence of data or logical entity that produces or consumes information. A data stream is a channel through which data travels from a source to a destination. This source or destination can be an input or output device, storage media or network computers.

A physical file can be read using  different types of streams, for example, FileInputStream or FileReader. Java uses such streams to perform various input and output operations. The standard input/output stream in Java is represented by three fields of the System class:

  • in: The standard input stream is used for reading characters of data.
  • out: The normal output stream is used to classically show the output on the screen or any other output medium.
  • err: This is the standard error stream.     

In Java, streams are required to perform all the input/output (I/O) operations. Thus, Stream classes help in:

  • Reading input from a stream.
  • Writing output to a stream.
  • Managing disk files.

Share data with a network of computers. To read or write data using Input/Output streams, the following steps need to be performed. They are:

  • Open a stream that ideas at an exact data source: a file, a socket, URL, and so on.    
  • Read or write data from/to this stream.
  • Close the stream.

Input and Output streams are abstract classes and are used for reading and writing of an unstructured sequence of bytes.The other input and output streams are subclasses of the basic Input and Output stream class and are used for reading and writing to a file.

The different types of byte streams can be used interchangeably as they inherit the structure of Input/Output stream class. For reading or writing bytes, a subclass of the InputStream or OutputStream class has to be used respectively.

File Class in Java

File class directly works with files and the file system.The files are named using the file-naming conventions of the host operating system. These conventions are encapsulated using the File class constants. A pathname can be absolute or relative.

In an absolute pathname, no other information is required in order to locate the required file as the pathname is complete. In a relative pathname, information is gathered from some other pathname. The classes in the java.io package resolves virtual pathnames beside the present user directory, which is named by the system property user.dir.

The directory methods in the File class allow creating, deleting, renaming, and listing of directories. The interfaces and classes defined by the java.nio.file package helps the Java virtual machine to access files, file systems, and file attributes. The toPath() method supports to get a Path that uses the abstract path. A File object uses this path to locate a file.

The constructors of the File class are as follows:

  • File(String dir path)
  • File(String parent, String child)
  • File(File file obj, String filename)
  • File(URL URL obj)

Methods of File Class

The methods in File class help to manipulate the file on the file system. Some of the methods in the File class are:

renameTo(File newname): Names the existing File object with the new name specified by the variable newname.
delete(): Deletes the file represented by the abstract path name.
exists(): Tests the existence of file or directory denoted by this abstract pathname.
getPath(): Converts the abstract pathname into a pathname string.
isFile(): Checks whether the file denoted by this abstract pathname is a normal file.
createNewFile(): Creates a new empty file whose name is the pathname of this file. It is only created when the file of a similar name does not exist.
media(): Creates the directory named by this abstract pathname.
toPath(): Returns a java.nio.file.Path object constructed from the abstract path.
toURI(): Constructs a file, URI. This file represents this abstract pathname.

These all about File Handling in java, Furthermore, I have made a video tutorial on this topic, I have shared the video tutorial on below, I hope video tutorials is very helpful and most beneficially for you. Basically, I have shared above complete knowledge File Handling in Java, but you must be watch  video tutorial and understand how does work it?  

File Handling in Java Tutorial in Urdu

Thanks for Watch Complete Video tutorial about File Handling in Java, after watch, I hope you have understood as well and you will learn it something new. Kindly, share my content on social networks and subscribe my website social networks pages like Facebook, Google+, Twitter, YouTube and Email for post updates. If you have any question / suggestion about this topic comment or email me after received your email or comment I will reply with your answer maximum 24 hours. Thanks Again for a visit, Read my Complete Article and Watch my Videos. Keep touch my website I will share popular programming Languages like C# and Windows App very soon.