0% found this document useful (0 votes)
15 views

Java ch-6

The document provides an overview of file handling in Java, detailing the use of the File class for operations such as creating, reading, updating, and deleting files. It explains the concept of streams, classifying them into byte and character streams for input and output operations. Additionally, it lists various methods associated with file handling and the importance of stream classes in managing data flow.

Uploaded by

anonymous1112acc
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PPTX, PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
15 views

Java ch-6

The document provides an overview of file handling in Java, detailing the use of the File class for operations such as creating, reading, updating, and deleting files. It explains the concept of streams, classifying them into byte and character streams for input and output operations. Additionally, it lists various methods associated with file handling and the importance of stream classes in managing data flow.

Uploaded by

anonymous1112acc
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PPTX, PDF, TXT or read online on Scribd
You are on page 1/ 16

Managing

Input/Output Files in
Java
Unit 6: Java Programming
Elementary Concepts:
File Handling in Java
 The File class from java.io package, allows us to work with files.
 Java has several methods for creating, reading, updating and deleting files.
 To use the File class, create an object of the class, and specify the filename
or directory name.
For instance,
//import
//import the
the File
File class
class
import java.io.File;
//specify
//specify the
the File
File name
name
File myobj=new
File("filename.txt");
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.

II. OutputStream (abstract class):


•The superclass for all output byte streams.
•It provides method for writing raw bytes of data.
Input stream classes
 The input stream is used to read data from numerous input devices like
keyboard, network, etc.
 InputStream is an abstract class, and because pf this, it is not useful by itself.

 However, its subclasses are used to read data.

 There are several subclasses of InputStream class-

i. AudioInputStream
ii. ByteArrayInputStream

iii. FileInputStream

iv. StringBufferInputStream

v. ObjectInputStream
 Creating an InputStream-

InputStream obj = new FileInputStream();


Output stream classes
Character stream classes
Creation of files
Reading/Writing characters
Reading/Writing Bytes
Handling Primitive Data
types
Strea Collection of bytes or characters

m Provides sequential access of


data

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

Input Output Reader Writer


stream stream
classes classes
THANKYOU!

Siya Lahoti (2230222)


Nikhil Gowda (2230223)
Utkarsh Shinde (2230224)
Sarwesh Lendal (2230225)
Vedant Navghare (2230226)
Karan Vanve (2230227)
Sakshi Karhale (2230228)

You might also like