Entri Blog
No Result
View All Result
Friday, August 12, 2022
  • State Level PSC
    • Kerala PSC
    • TNPSC
    • APPSC
    • TSPSC
    • BPSC
    • Karnataka PSC
    • MPPSC
    • UPPSC
  • Banking
  • SSC
  • Railway
  • Other Govt. Exam
  • TET
    • APTET
    • CTET
    • DSSSB
    • Karnataka TET
    • Kerala TET
    • KVS
    • MPTET
    • SUPER TET
    • TNTET
    • TSTET
    • UPTET
FREE GK TEST: SIGNUP NOW
Entri Blog
  • State Level PSC
    • Kerala PSC
    • TNPSC
    • APPSC
    • TSPSC
    • BPSC
    • Karnataka PSC
    • MPPSC
    • UPPSC
  • Banking
  • SSC
  • Railway
  • Other Govt. Exam
  • TET
    • APTET
    • CTET
    • DSSSB
    • Karnataka TET
    • Kerala TET
    • KVS
    • MPTET
    • SUPER TET
    • TNTET
    • TSTET
    • UPTET
No Result
View All Result
Entri Blog
Free GK Test
banner top article banner top article
Home Articles

Learn About File Handling in Java

by Shibani Ghosh
May 21, 2022
in Articles, Data Science and Machine Learning, Digital Marketing, Java Programming, React Native
Learn About File Handling in Java
Share on FacebookShare on WhatsAppShare on Telegram

Java is one of the most popular programming languages that provides extensive support to various functionalities like databases, sockets, etc. One such functionality is File Handling in Java. File Handling is necessary to perform various tasks on a file, such as reading, writing, etc. In this article, I will tell you what are the various file operations in Java.

What is File Handling in Java?

Java file handling implies reading from and writing data to a file. The File class from the java.io package, allows us to work with different formats of files. In order to use the File class, you need to create an object of the class and specify the filename or directory name.

Check out the Entri App for more details on Data Science and Machine Learning!

Why File Handling is Required?

  • File handling in java is an integral part of any programming language as file handling enables us to store the output of any particular program in a file and allows us to perform certain operations on it.
  • In simple words, file handling means reading and writing data to a file.

Streams in Java

In Java, a sequence of data is known as a stream. This concept is used to perform I/O operations i.e, Input and Output on a file. There are two types of streams in this.

Input Stream

The Java InputStream class is the superclass of all input streams. The input stream is used to read data from numerous input devices like the keyboard, network, etc.

Know more about file class in java!

S No. Method Description
1 read()
Reads one byte of data from the input stream.
2 read(byte[] array)()
Reads byte from the stream and stores that byte in the specified array.
3 mark()
It marks the position in the input stream until the data has been read.
4 available()
Returns the number of bytes available in the input stream.
5 markSupported()
It checks if the mark() method and the reset() method is supported in the stream.
6 reset()
Returns the control to the point where the mark was set inside the stream.
7 skips()
Skips and removes a particular number of bytes from the input stream.
8 close()
Closes the input stream.

Subscribe to Entri for more details on Data Science and Machine Learning!

Output Stream

The output stream is used to write data to numerous output devices like the monitor, file, etc. OutputStream is an abstract superclass that represents an output stream.

S. No. Method Description
1 write()
Writes the specified byte to the output stream.
2 write(byte[] array)
Writes the bytes which are inside a specific array to the output stream.
3 close()
Closes the output stream.
4 flush()
Forces to write all the data present in an output stream to the destination.

Based on the data type, there are two types of streams :

1. Byte Stream:

This stream is used to read or write byte data. The byte stream is again subdivided into two types which are as follows:

  • Byte Input Stream: Used to read byte data from different devices.
  • Byte Output Stream: Used to write byte data to different devices.

Take a try for Data Science and Machine Learning now!

2. Character Stream:

This stream is used to read or write character data. Character stream is again subdivided into 2 types which are as follows:

  • Character Input Stream: Used to read character data from different devices.
  • Character Output Stream: Used to write character data to different devices.

In Java, with the help of File Class, we can work with files. This File Class is inside the java.io package. The File class can be used by creating an object of the class and then specifying the name of the file.

Prepare for Data Science and Machine Learning with Entri!

Entri provides video classes as well on various important topics by the excellent faculties. One will get revision modules, monthly tests based on the classes. You will be provided with an online platform to prepare for the exam. It also gives you access to clarify your doubts.

Share61SendShare
Shibani Ghosh

Shibani Ghosh

Pouring out my thoughts through words!

Related Posts

What are the Levels of Language Proficiency
Articles

What are the Levels of Language Proficiency?

July 22, 2022
NVS TGT, PGT Cut Off 2022 - Previous Year, Expected Cut Off
Articles

NVS TGT, PGT Cut Off 2022 – Previous Year, Expected Cut Off

July 22, 2022
Haryana PSC ADO Salary 2022- Pay Scale, In Hand Salary
Articles

Haryana PSC ADO Salary 2022- Pay Scale, In Hand Salary

July 22, 2022
Next Post
Kerala PSC Clay Worker Notification 2022

Kerala PSC Clay Worker Notification 2022

Discussion about this post

Latest Posts

  • Haryana CET 2022 Exam Dates Out
  • What Is Data Mining? A Complete Guide
  • Kerala PSC Lab Assistant Syllabus and Exam Pattern 2022 – Check Exam Pattern, Download Syllabus
  • RRC WCR Recruitment 2022: Apply for 102 Posts
  • What Are the Different Types of SEO?

Trending Posts

  • states of india and their capitals and languages

    List of 28 States of India and their Capitals and Languages

    147279 shares
    Share 58909 Tweet 36818
  • List of Government Banks in India 2022: All you need to know

    58814 shares
    Share 23526 Tweet 14704
  • TNPSC Group 2 Posts and Salary Details 2022

    37207 shares
    Share 14883 Tweet 9302
  • Kerala Devaswom Board LDC Syllabus 2022 – Download PDF

    1305 shares
    Share 522 Tweet 326
  • New Map of India with States and Capitals 2022

    27990 shares
    Share 11196 Tweet 6997

Company

  • Become a teacher
  • Login to Entri Web

Quick Links

  • Articles
  • Videos
  • Entri Daily Quiz Practice
  • Current Affairs & GK
  • News Capsule – eBook
  • Preparation Tips
  • Kerala PSC Gold
  • Entri Skilling

Popular Exam

  • IBPS Exam
  • SBI Exam
  • Railway RRB Exam
  • Kerala PSC
  • Tamil Nadu PSC
  • Telangana PSC
  • Andhra Pradesh PSC
  • MPPSC
  • UPPSC
  • Karnataka PSC
  • Staff Selection Commission Exam

© 2021 Entri.app - Privacy Policy | Terms of Service

No Result
View All Result
  • State Level PSC
    • Kerala PSC
    • TNPSC
    • APPSC
    • TSPSC
    • BPSC
    • Karnataka PSC
    • MPPSC
    • UPPSC
  • Banking
  • SSC
  • Railway
  • Other Govt. Exam
  • TET
    • APTET
    • CTET
    • DSSSB
    • Karnataka TET
    • Kerala TET
    • KVS
    • MPTET
    • SUPER TET
    • TNTET
    • TSTET
    • UPTET

© 2021 Entri.app - Privacy Policy | Terms of Service

Try After Few Days!
30% OFF
Next time
Next time
Almost!
70% OFF
20% OFF
Next Time
Next time
Almost!
40% OFF
60% OFF
Unlucky
Spin the Wheel to Win FREE PREP on our courses! PSC, SSC, RRB, Banking, TET
Enter your email address and spin the wheel. This is your chance to win amazing discounts!
Our in-house rules:
  • One game per user
  • Cheaters will be disqualified.
  • Offer applicable for 1st time ENTRI users!