Location via proxy:   [ UP ]  
[Report a bug]   [Manage cookies]                
0% found this document useful (0 votes)
9 views

managing input/output files in java

The document provides an overview of managing input/output files in Java, detailing methods for file handling such as checking readability, writability, and existence of files. It introduces the concept of streams as fundamental units for I/O operations, distinguishing between byte streams and character streams. Additionally, it lists various input and output stream classes used for reading and writing data in Java.

Uploaded by

anonymous1112acc
Copyright
© © All Rights Reserved
Available Formats
Download as PPTX, PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
9 views

managing input/output files in java

The document provides an overview of managing input/output files in Java, detailing methods for file handling such as checking readability, writability, and existence of files. It introduces the concept of streams as fundamental units for I/O operations, distinguishing between byte streams and character streams. Additionally, it lists various input and output stream classes used for reading and writing data in Java.

Uploaded by

anonymous1112acc
Copyright
© © All Rights Reserved
Available Formats
Download as PPTX, PDF, TXT or read online on Scribd
You are on page 1/ 9

Managing

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.

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 of 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
 OutputStream is an abstract class that provides a framework for creating output
streams to write byte data.
 Classes that extend OutputStream should provide implementations for the abstract
methods defined in the class.
 Subclasses: Includes,

i. FileOutputStream,
ii. ByteArrayOutputStream,
iii. FilterOutputStream,
iv. ObjectOutputStream,
v. PipedOutputStream
 Creating an OutputStream-

OutputStream os = new FileOutputStream("output.txt");


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