managing input/output files in java
managing input/output files in java
Input/Output Files in
Java
Unit 6: Java Programming
Sr.
Method Type Description
no.
Test whether the file is
1. canRead() Boolean
read-able or not
Tests whether the file is
2. canWrite() Boolean
write-able or not
3. CreateNewFile() Boolean Creates an empty file
4. delete() Boolean Deletes a file
Tests whether the file
5. exists() Boolean
exists
Returns the name of
6. getName() string
the file
Returns the absolute
7. getAbsolutepath() string pathname of the
filename
Returns the size of the
8. length() Long
file in bytes
Returns the array of the
9. list() string[]
files in the dictionary
Checks if a path refers
Why File Handling is
required?
File handling 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.
In java, the concept Stream is used in order to perform I/O operations on a file.
Introduction & Concept of
Streams.
Stream represents the sequence of data flowing from source to a
destination.
Streams are the fundamental units for input and output operations in Java.
A stream can be classified as-
Byte Streams : handles raw bytes of data.
i. Input Stream (for reading)
ii. Output Stream (for writing)
character Stream : handles characters (text data).
i. Reader (for reading)
ii. Writer (for writing)
Overview of Byte stream
classes:
I. InputStream (abstract class):
•The superclass for all input byte streams.
•It provides methods for reading raw bytes of data.
i. AudioInputStream
ii. ByteArrayInputStream
iii. FileInputStream
iv. StringBufferInputStream
v. ObjectInputStream
Creating an InputStream-
i. FileOutputStream,
ii. ByteArrayOutputStream,
iii. FilterOutputStream,
iv. ObjectOutputStream,
v. PipedOutputStream
Creating an OutputStream-
J System.out
O/P stream
System.in
I/P stream
System.err
Error stream
I/P stream
A O/P stream
Source
Read
V Destination
Write
Java Stream Classes
Operatio
n A Operation
Byte stream classes character stream
Applicatio
n
classes