SlideShare ist ein Scribd-Unternehmen logo
1 von 13
• FileInputStream
• FileOutputStream
• InputStreamReader
• OutputStreamWriter
• FileReader
• FileWriter
Topic
FileInputStream
 Java FileInputStream class obtains input bytes from a file. It is
used for reading streams of raw bytes such as image data. For
reading stream of characters, consider using Filereader.
 It should be used to read byte-oriented data for example to read
Image, audio, video etc.
--------------
--------------
--------------
--------------
1100110011
Java
Application
f.txt
fin
Example :
import java.io.*;
class SimpleRead{
public static void main(String args[]){
try{
FileInputSteram fin=new FileInputStream("abc.txt");
int i=0;
while((i=fin.read())!='-1){
System.out.println((char)i);
}
fin.close();
}
catch(exception e){
system.out.println(e);
}
}
}
FileoutputStream
 Java FileOutputStream is an outputstream for writing data to a file.
 If you have to write primitive values then use FileOutputStream.instead,for
character-oriented data,prefer FileWriter.But you can write byte-oriented as
well as character-oriented data.
Java
Application
1100110011
---------------
---------------
---------------
---------------
fout
f.txt
Example :
import java.io.*;
class Test{
public static void main(String args[]){
try{
FileOutputStream fout=new FileOutputStream("abc.txt");
String s="Sachin Tendulkar is my favourite player";
byte b[]=s.getbytes();//converting string into byte array
fout.write(b);
fout.close();
System.out.println("success...");
} catch(Exception e)
{
System.out.println(e);
}
}
}
InputStreamReader
 The java.io.InputStreamReader class is a bridge from byte stream to
character stream.it reads bytes and decodes them into characters using a
specified charset.
S.N. Constructor & Description
1
InputStreamReader(InputStream in)
This creates an InputStreamReader that uses the default charset.
2
InputStreamReader(InputStream in, Charset cs)
This creates an InputStreamReader that uses the given charset.
3 InputStreamReader(InputStreamReader in,CharsetDecoder dec)
This creates an InputStreamReader that uses the given charset decoder
4 InputStreamReader(InputStream in, String charsetName)
This creates an InputStreamReader that uses the named charset.
• Methods:
S.N. Method & Desription
1 Void close()
This method close the stream and releases any system resources
Associated with it.
2 String getEncoding()
This method returns the name of the character encoding
Being used by this stream.
3 Int read()
This method reads a single character.
4 Int read(char[] cbuf,int offset,int length)
This method reads characters into a portion of an array.
5 Boolean ready()
This method tells whether this stream is ready to be read.
OutputStreamWriter
 The java.io.OutputStreamWriter class is a bridge from character streams to byte
streams.
 characters written to it are encoded into bytes using a specified charset.
• Constructors:
S.N. Constructor & Description
1
OutputStreamWriter(OutputStream out)
This creates an OutputStreamWriter that uses the default character encoding
2
OutputStreamWriter(OutputStream out, Charset cs)
This creates an outputStreamWriter that uses the given charset.
3 OutputStreamWriter(OutputStreamWriter out,CharsetEncoder enc)
This creates an OutputStreamWriter that uses the given charset encoder
4 OutputStreamWriter(OutputStream out, String charsetName)
This creates an OutputStreamWriter that uses the named charset.
• Methods:
S.N. Method & Desription
1 Void close()
This method close the stream,flushing it first.
2 Void flush()
This method flushes the stream.
3 Int read()
This method returns the name of the character encoding
Being used by this stream.
4 Void write(char[] cbuf,int off,int len)
This method writes a portion of an array of characters.
5 void write(int c)
This method writes a single character.
void write(string str,int off,int len)
This method writes a portion of a string.
6
Filereader
 This class inherits from the InputStreamReader class. FileReader is used for
reading streams of characters.
 This class has several constructors to create required objects. Below given are the list of
constructors provided by the FileReader class.
• Constructors:
S.N. Constructor & Description
1 FileReader(File file)
This constructor creates a new FileReader, given the File to read from.
2 FileReader(FileDescriptor fd)
This constructor creates a new FileReader, given the FileDescriptor to read from.
3 FileReader(String fileName)
This constructor creates a new FileReader, given the name of the file to read
from.
File Writer
 This class inherits from the OutputStreamWriter class. The class is used for
writing streams of characters.
 This class has serveral constructors to create required objects. Below
given is the list of them.
• Constructors:
S.N. Constructor & Description
1 FileWriter(File file)
This constructor creates a new FileWriter, given a File object.
2 FileWriter(File file, Boolean append)
This constructor creates a FileWriter object given a file object. With a Boolean
Indicating whether or not to append the data written.
3 FileReader(FileDescriptor fd)
This constructor creates a FileWriter object associated with the given file
descriptor
4 FileWriter(string fileName)
This constructor creates a FileWriter object, given a file name.
5 FileWriter(string filename, Boolean append)
This constructor creates a FileWriter object given a file name with a
Boolean indicating whether or not to append the data written.
• Methods:
S.N. Method with Desription
1 Public Void write(int c) throws ioException
Write a single character.
2 Public Void write(char [] c,int offset,int len)
Write a portion of an array of characters starting from offset and
with a length of len
3 Public Void write(String s,int off,int len)
Write a portion of a String starting from offset and with a length
of len
Java

Weitere ähnliche Inhalte

Was ist angesagt?

Java - File Input Output Concepts
Java - File Input Output ConceptsJava - File Input Output Concepts
Java - File Input Output ConceptsVicter Paul
 
Understanding java streams
Understanding java streamsUnderstanding java streams
Understanding java streamsShahjahan Samoon
 
File Input & Output
File Input & OutputFile Input & Output
File Input & OutputPRN USM
 
Chapter 12 - File Input and Output
Chapter 12 - File Input and OutputChapter 12 - File Input and Output
Chapter 12 - File Input and OutputEduardo Bergavera
 
[Java] #7 - Input & Output Stream
[Java] #7 - Input & Output Stream[Java] #7 - Input & Output Stream
[Java] #7 - Input & Output StreamGhadeer AlHasan
 
Java Input Output (java.io.*)
Java Input Output (java.io.*)Java Input Output (java.io.*)
Java Input Output (java.io.*)Om Ganesh
 
Multithreading in java
Multithreading in javaMultithreading in java
Multithreading in javaKavitha713564
 
I/O in java Part 1
I/O in java Part 1I/O in java Part 1
I/O in java Part 1ashishspace
 
IO In Java
IO In JavaIO In Java
IO In Javaparag
 
7 streams and error handling in java
7 streams and error handling in java7 streams and error handling in java
7 streams and error handling in javaJyoti Verma
 
IO and serialization
IO and serializationIO and serialization
IO and serializationbackdoor
 
L21 io streams
L21 io streamsL21 io streams
L21 io streamsteach4uin
 
14 file handling
14 file handling14 file handling
14 file handlingAPU
 
Input output files in java
Input output files in javaInput output files in java
Input output files in javaKavitha713564
 
Byte stream classes.49
Byte stream classes.49Byte stream classes.49
Byte stream classes.49myrajendra
 

Was ist angesagt? (20)

Java - File Input Output Concepts
Java - File Input Output ConceptsJava - File Input Output Concepts
Java - File Input Output Concepts
 
Understanding java streams
Understanding java streamsUnderstanding java streams
Understanding java streams
 
Handling I/O in Java
Handling I/O in JavaHandling I/O in Java
Handling I/O in Java
 
File Input & Output
File Input & OutputFile Input & Output
File Input & Output
 
Java I/o streams
Java I/o streamsJava I/o streams
Java I/o streams
 
Java stream
Java streamJava stream
Java stream
 
Chapter 12 - File Input and Output
Chapter 12 - File Input and OutputChapter 12 - File Input and Output
Chapter 12 - File Input and Output
 
[Java] #7 - Input & Output Stream
[Java] #7 - Input & Output Stream[Java] #7 - Input & Output Stream
[Java] #7 - Input & Output Stream
 
Java I/O
Java I/OJava I/O
Java I/O
 
Java Input Output (java.io.*)
Java Input Output (java.io.*)Java Input Output (java.io.*)
Java Input Output (java.io.*)
 
Files in java
Files in javaFiles in java
Files in java
 
Multithreading in java
Multithreading in javaMultithreading in java
Multithreading in java
 
I/O in java Part 1
I/O in java Part 1I/O in java Part 1
I/O in java Part 1
 
IO In Java
IO In JavaIO In Java
IO In Java
 
7 streams and error handling in java
7 streams and error handling in java7 streams and error handling in java
7 streams and error handling in java
 
IO and serialization
IO and serializationIO and serialization
IO and serialization
 
L21 io streams
L21 io streamsL21 io streams
L21 io streams
 
14 file handling
14 file handling14 file handling
14 file handling
 
Input output files in java
Input output files in javaInput output files in java
Input output files in java
 
Byte stream classes.49
Byte stream classes.49Byte stream classes.49
Byte stream classes.49
 

Ähnlich wie Java

Java program file I/O
Java program file I/OJava program file I/O
Java program file I/ONem Sothea
 
File Input and output.pptx
File Input  and output.pptxFile Input  and output.pptx
File Input and output.pptxcherryreddygannu
 
Input/Output Exploring java.io
Input/Output Exploring java.ioInput/Output Exploring java.io
Input/Output Exploring java.ioNilaNila16
 
File Handling in Java Oop presentation
File Handling in Java Oop presentationFile Handling in Java Oop presentation
File Handling in Java Oop presentationAzeemaj101
 
File Handling in Java.pdf
File Handling in Java.pdfFile Handling in Java.pdf
File Handling in Java.pdfSudhanshiBakre1
 
Itp 120 Chapt 19 2009 Binary Input & Output
Itp 120 Chapt 19 2009 Binary Input & OutputItp 120 Chapt 19 2009 Binary Input & Output
Itp 120 Chapt 19 2009 Binary Input & Outputphanleson
 
Stream In Java.pptx
Stream In Java.pptxStream In Java.pptx
Stream In Java.pptxssuser9d7049
 
Chapter 10.3
Chapter 10.3Chapter 10.3
Chapter 10.3sotlsoc
 
Java IO, Serialization
Java IO, Serialization Java IO, Serialization
Java IO, Serialization Hitesh-Java
 
Session 22 - Java IO, Serialization
Session 22 - Java IO, SerializationSession 22 - Java IO, Serialization
Session 22 - Java IO, SerializationPawanMM
 
Computer science input and output BASICS.pptx
Computer science input and output BASICS.pptxComputer science input and output BASICS.pptx
Computer science input and output BASICS.pptxRathanMB
 
Advanced programming ch2
Advanced programming ch2Advanced programming ch2
Advanced programming ch2Gera Paulos
 
CSE3146-ADV JAVA M2.pdf
CSE3146-ADV JAVA M2.pdfCSE3146-ADV JAVA M2.pdf
CSE3146-ADV JAVA M2.pdfVithalReddy3
 
Buffer and scanner
Buffer and scannerBuffer and scanner
Buffer and scannerArif Ullah
 
inputoutputstreams-140612032817-phpapp02.pdf
inputoutputstreams-140612032817-phpapp02.pdfinputoutputstreams-140612032817-phpapp02.pdf
inputoutputstreams-140612032817-phpapp02.pdfhemanth248901
 

Ähnlich wie Java (20)

Java Day-6
Java Day-6Java Day-6
Java Day-6
 
Java program file I/O
Java program file I/OJava program file I/O
Java program file I/O
 
File Input and output.pptx
File Input  and output.pptxFile Input  and output.pptx
File Input and output.pptx
 
Io Streams
Io StreamsIo Streams
Io Streams
 
Input/Output Exploring java.io
Input/Output Exploring java.ioInput/Output Exploring java.io
Input/Output Exploring java.io
 
IOStream.pptx
IOStream.pptxIOStream.pptx
IOStream.pptx
 
File Handling in Java Oop presentation
File Handling in Java Oop presentationFile Handling in Java Oop presentation
File Handling in Java Oop presentation
 
Unit IV Notes.docx
Unit IV Notes.docxUnit IV Notes.docx
Unit IV Notes.docx
 
File Handling in Java.pdf
File Handling in Java.pdfFile Handling in Java.pdf
File Handling in Java.pdf
 
Itp 120 Chapt 19 2009 Binary Input & Output
Itp 120 Chapt 19 2009 Binary Input & OutputItp 120 Chapt 19 2009 Binary Input & Output
Itp 120 Chapt 19 2009 Binary Input & Output
 
Stream In Java.pptx
Stream In Java.pptxStream In Java.pptx
Stream In Java.pptx
 
Chapter 10.3
Chapter 10.3Chapter 10.3
Chapter 10.3
 
Java IO, Serialization
Java IO, Serialization Java IO, Serialization
Java IO, Serialization
 
Session 22 - Java IO, Serialization
Session 22 - Java IO, SerializationSession 22 - Java IO, Serialization
Session 22 - Java IO, Serialization
 
05io
05io05io
05io
 
Computer science input and output BASICS.pptx
Computer science input and output BASICS.pptxComputer science input and output BASICS.pptx
Computer science input and output BASICS.pptx
 
Advanced programming ch2
Advanced programming ch2Advanced programming ch2
Advanced programming ch2
 
CSE3146-ADV JAVA M2.pdf
CSE3146-ADV JAVA M2.pdfCSE3146-ADV JAVA M2.pdf
CSE3146-ADV JAVA M2.pdf
 
Buffer and scanner
Buffer and scannerBuffer and scanner
Buffer and scanner
 
inputoutputstreams-140612032817-phpapp02.pdf
inputoutputstreams-140612032817-phpapp02.pdfinputoutputstreams-140612032817-phpapp02.pdf
inputoutputstreams-140612032817-phpapp02.pdf
 

Kürzlich hochgeladen

Thermal Engineering Unit - I & II . ppt
Thermal Engineering  Unit - I & II . pptThermal Engineering  Unit - I & II . ppt
Thermal Engineering Unit - I & II . pptDineshKumar4165
 
PVC VS. FIBERGLASS (FRP) GRAVITY SEWER - UNI BELL
PVC VS. FIBERGLASS (FRP) GRAVITY SEWER - UNI BELLPVC VS. FIBERGLASS (FRP) GRAVITY SEWER - UNI BELL
PVC VS. FIBERGLASS (FRP) GRAVITY SEWER - UNI BELLManishPatel169454
 
Call for Papers - International Journal of Intelligent Systems and Applicatio...
Call for Papers - International Journal of Intelligent Systems and Applicatio...Call for Papers - International Journal of Intelligent Systems and Applicatio...
Call for Papers - International Journal of Intelligent Systems and Applicatio...Christo Ananth
 
KubeKraft presentation @CloudNativeHooghly
KubeKraft presentation @CloudNativeHooghlyKubeKraft presentation @CloudNativeHooghly
KubeKraft presentation @CloudNativeHooghlysanyuktamishra911
 
Call Girls Pimpri Chinchwad Call Me 7737669865 Budget Friendly No Advance Boo...
Call Girls Pimpri Chinchwad Call Me 7737669865 Budget Friendly No Advance Boo...Call Girls Pimpri Chinchwad Call Me 7737669865 Budget Friendly No Advance Boo...
Call Girls Pimpri Chinchwad Call Me 7737669865 Budget Friendly No Advance Boo...roncy bisnoi
 
result management system report for college project
result management system report for college projectresult management system report for college project
result management system report for college projectTonystark477637
 
Extrusion Processes and Their Limitations
Extrusion Processes and Their LimitationsExtrusion Processes and Their Limitations
Extrusion Processes and Their Limitations120cr0395
 
University management System project report..pdf
University management System project report..pdfUniversity management System project report..pdf
University management System project report..pdfKamal Acharya
 
ONLINE FOOD ORDER SYSTEM PROJECT REPORT.pdf
ONLINE FOOD ORDER SYSTEM PROJECT REPORT.pdfONLINE FOOD ORDER SYSTEM PROJECT REPORT.pdf
ONLINE FOOD ORDER SYSTEM PROJECT REPORT.pdfKamal Acharya
 
Call Girls Walvekar Nagar Call Me 7737669865 Budget Friendly No Advance Booking
Call Girls Walvekar Nagar Call Me 7737669865 Budget Friendly No Advance BookingCall Girls Walvekar Nagar Call Me 7737669865 Budget Friendly No Advance Booking
Call Girls Walvekar Nagar Call Me 7737669865 Budget Friendly No Advance Bookingroncy bisnoi
 
Booking open Available Pune Call Girls Pargaon 6297143586 Call Hot Indian Gi...
Booking open Available Pune Call Girls Pargaon  6297143586 Call Hot Indian Gi...Booking open Available Pune Call Girls Pargaon  6297143586 Call Hot Indian Gi...
Booking open Available Pune Call Girls Pargaon 6297143586 Call Hot Indian Gi...Call Girls in Nagpur High Profile
 
Vivazz, Mieres Social Housing Design Spain
Vivazz, Mieres Social Housing Design SpainVivazz, Mieres Social Housing Design Spain
Vivazz, Mieres Social Housing Design Spaintimesproduction05
 
Structural Analysis and Design of Foundations: A Comprehensive Handbook for S...
Structural Analysis and Design of Foundations: A Comprehensive Handbook for S...Structural Analysis and Design of Foundations: A Comprehensive Handbook for S...
Structural Analysis and Design of Foundations: A Comprehensive Handbook for S...Dr.Costas Sachpazis
 
The Most Attractive Pune Call Girls Budhwar Peth 8250192130 Will You Miss Thi...
The Most Attractive Pune Call Girls Budhwar Peth 8250192130 Will You Miss Thi...The Most Attractive Pune Call Girls Budhwar Peth 8250192130 Will You Miss Thi...
The Most Attractive Pune Call Girls Budhwar Peth 8250192130 Will You Miss Thi...ranjana rawat
 
Double rodded leveling 1 pdf activity 01
Double rodded leveling 1 pdf activity 01Double rodded leveling 1 pdf activity 01
Double rodded leveling 1 pdf activity 01KreezheaRecto
 
VIP Model Call Girls Kothrud ( Pune ) Call ON 8005736733 Starting From 5K to ...
VIP Model Call Girls Kothrud ( Pune ) Call ON 8005736733 Starting From 5K to ...VIP Model Call Girls Kothrud ( Pune ) Call ON 8005736733 Starting From 5K to ...
VIP Model Call Girls Kothrud ( Pune ) Call ON 8005736733 Starting From 5K to ...SUHANI PANDEY
 
FULL ENJOY Call Girls In Mahipalpur Delhi Contact Us 8377877756
FULL ENJOY Call Girls In Mahipalpur Delhi Contact Us 8377877756FULL ENJOY Call Girls In Mahipalpur Delhi Contact Us 8377877756
FULL ENJOY Call Girls In Mahipalpur Delhi Contact Us 8377877756dollysharma2066
 

Kürzlich hochgeladen (20)

Thermal Engineering Unit - I & II . ppt
Thermal Engineering  Unit - I & II . pptThermal Engineering  Unit - I & II . ppt
Thermal Engineering Unit - I & II . ppt
 
Roadmap to Membership of RICS - Pathways and Routes
Roadmap to Membership of RICS - Pathways and RoutesRoadmap to Membership of RICS - Pathways and Routes
Roadmap to Membership of RICS - Pathways and Routes
 
PVC VS. FIBERGLASS (FRP) GRAVITY SEWER - UNI BELL
PVC VS. FIBERGLASS (FRP) GRAVITY SEWER - UNI BELLPVC VS. FIBERGLASS (FRP) GRAVITY SEWER - UNI BELL
PVC VS. FIBERGLASS (FRP) GRAVITY SEWER - UNI BELL
 
Call for Papers - International Journal of Intelligent Systems and Applicatio...
Call for Papers - International Journal of Intelligent Systems and Applicatio...Call for Papers - International Journal of Intelligent Systems and Applicatio...
Call for Papers - International Journal of Intelligent Systems and Applicatio...
 
KubeKraft presentation @CloudNativeHooghly
KubeKraft presentation @CloudNativeHooghlyKubeKraft presentation @CloudNativeHooghly
KubeKraft presentation @CloudNativeHooghly
 
Call Girls Pimpri Chinchwad Call Me 7737669865 Budget Friendly No Advance Boo...
Call Girls Pimpri Chinchwad Call Me 7737669865 Budget Friendly No Advance Boo...Call Girls Pimpri Chinchwad Call Me 7737669865 Budget Friendly No Advance Boo...
Call Girls Pimpri Chinchwad Call Me 7737669865 Budget Friendly No Advance Boo...
 
result management system report for college project
result management system report for college projectresult management system report for college project
result management system report for college project
 
Extrusion Processes and Their Limitations
Extrusion Processes and Their LimitationsExtrusion Processes and Their Limitations
Extrusion Processes and Their Limitations
 
University management System project report..pdf
University management System project report..pdfUniversity management System project report..pdf
University management System project report..pdf
 
ONLINE FOOD ORDER SYSTEM PROJECT REPORT.pdf
ONLINE FOOD ORDER SYSTEM PROJECT REPORT.pdfONLINE FOOD ORDER SYSTEM PROJECT REPORT.pdf
ONLINE FOOD ORDER SYSTEM PROJECT REPORT.pdf
 
Call Girls Walvekar Nagar Call Me 7737669865 Budget Friendly No Advance Booking
Call Girls Walvekar Nagar Call Me 7737669865 Budget Friendly No Advance BookingCall Girls Walvekar Nagar Call Me 7737669865 Budget Friendly No Advance Booking
Call Girls Walvekar Nagar Call Me 7737669865 Budget Friendly No Advance Booking
 
Booking open Available Pune Call Girls Pargaon 6297143586 Call Hot Indian Gi...
Booking open Available Pune Call Girls Pargaon  6297143586 Call Hot Indian Gi...Booking open Available Pune Call Girls Pargaon  6297143586 Call Hot Indian Gi...
Booking open Available Pune Call Girls Pargaon 6297143586 Call Hot Indian Gi...
 
Vivazz, Mieres Social Housing Design Spain
Vivazz, Mieres Social Housing Design SpainVivazz, Mieres Social Housing Design Spain
Vivazz, Mieres Social Housing Design Spain
 
Structural Analysis and Design of Foundations: A Comprehensive Handbook for S...
Structural Analysis and Design of Foundations: A Comprehensive Handbook for S...Structural Analysis and Design of Foundations: A Comprehensive Handbook for S...
Structural Analysis and Design of Foundations: A Comprehensive Handbook for S...
 
The Most Attractive Pune Call Girls Budhwar Peth 8250192130 Will You Miss Thi...
The Most Attractive Pune Call Girls Budhwar Peth 8250192130 Will You Miss Thi...The Most Attractive Pune Call Girls Budhwar Peth 8250192130 Will You Miss Thi...
The Most Attractive Pune Call Girls Budhwar Peth 8250192130 Will You Miss Thi...
 
Double rodded leveling 1 pdf activity 01
Double rodded leveling 1 pdf activity 01Double rodded leveling 1 pdf activity 01
Double rodded leveling 1 pdf activity 01
 
Water Industry Process Automation & Control Monthly - April 2024
Water Industry Process Automation & Control Monthly - April 2024Water Industry Process Automation & Control Monthly - April 2024
Water Industry Process Automation & Control Monthly - April 2024
 
VIP Model Call Girls Kothrud ( Pune ) Call ON 8005736733 Starting From 5K to ...
VIP Model Call Girls Kothrud ( Pune ) Call ON 8005736733 Starting From 5K to ...VIP Model Call Girls Kothrud ( Pune ) Call ON 8005736733 Starting From 5K to ...
VIP Model Call Girls Kothrud ( Pune ) Call ON 8005736733 Starting From 5K to ...
 
FULL ENJOY Call Girls In Mahipalpur Delhi Contact Us 8377877756
FULL ENJOY Call Girls In Mahipalpur Delhi Contact Us 8377877756FULL ENJOY Call Girls In Mahipalpur Delhi Contact Us 8377877756
FULL ENJOY Call Girls In Mahipalpur Delhi Contact Us 8377877756
 
(INDIRA) Call Girl Aurangabad Call Now 8617697112 Aurangabad Escorts 24x7
(INDIRA) Call Girl Aurangabad Call Now 8617697112 Aurangabad Escorts 24x7(INDIRA) Call Girl Aurangabad Call Now 8617697112 Aurangabad Escorts 24x7
(INDIRA) Call Girl Aurangabad Call Now 8617697112 Aurangabad Escorts 24x7
 

Java

  • 1. • FileInputStream • FileOutputStream • InputStreamReader • OutputStreamWriter • FileReader • FileWriter Topic
  • 2. FileInputStream  Java FileInputStream class obtains input bytes from a file. It is used for reading streams of raw bytes such as image data. For reading stream of characters, consider using Filereader.  It should be used to read byte-oriented data for example to read Image, audio, video etc. -------------- -------------- -------------- -------------- 1100110011 Java Application f.txt fin
  • 3. Example : import java.io.*; class SimpleRead{ public static void main(String args[]){ try{ FileInputSteram fin=new FileInputStream("abc.txt"); int i=0; while((i=fin.read())!='-1){ System.out.println((char)i); } fin.close(); } catch(exception e){ system.out.println(e); } } }
  • 4. FileoutputStream  Java FileOutputStream is an outputstream for writing data to a file.  If you have to write primitive values then use FileOutputStream.instead,for character-oriented data,prefer FileWriter.But you can write byte-oriented as well as character-oriented data. Java Application 1100110011 --------------- --------------- --------------- --------------- fout f.txt
  • 5. Example : import java.io.*; class Test{ public static void main(String args[]){ try{ FileOutputStream fout=new FileOutputStream("abc.txt"); String s="Sachin Tendulkar is my favourite player"; byte b[]=s.getbytes();//converting string into byte array fout.write(b); fout.close(); System.out.println("success..."); } catch(Exception e) { System.out.println(e); } } }
  • 6. InputStreamReader  The java.io.InputStreamReader class is a bridge from byte stream to character stream.it reads bytes and decodes them into characters using a specified charset. S.N. Constructor & Description 1 InputStreamReader(InputStream in) This creates an InputStreamReader that uses the default charset. 2 InputStreamReader(InputStream in, Charset cs) This creates an InputStreamReader that uses the given charset. 3 InputStreamReader(InputStreamReader in,CharsetDecoder dec) This creates an InputStreamReader that uses the given charset decoder 4 InputStreamReader(InputStream in, String charsetName) This creates an InputStreamReader that uses the named charset.
  • 7. • Methods: S.N. Method & Desription 1 Void close() This method close the stream and releases any system resources Associated with it. 2 String getEncoding() This method returns the name of the character encoding Being used by this stream. 3 Int read() This method reads a single character. 4 Int read(char[] cbuf,int offset,int length) This method reads characters into a portion of an array. 5 Boolean ready() This method tells whether this stream is ready to be read.
  • 8. OutputStreamWriter  The java.io.OutputStreamWriter class is a bridge from character streams to byte streams.  characters written to it are encoded into bytes using a specified charset. • Constructors: S.N. Constructor & Description 1 OutputStreamWriter(OutputStream out) This creates an OutputStreamWriter that uses the default character encoding 2 OutputStreamWriter(OutputStream out, Charset cs) This creates an outputStreamWriter that uses the given charset. 3 OutputStreamWriter(OutputStreamWriter out,CharsetEncoder enc) This creates an OutputStreamWriter that uses the given charset encoder 4 OutputStreamWriter(OutputStream out, String charsetName) This creates an OutputStreamWriter that uses the named charset.
  • 9. • Methods: S.N. Method & Desription 1 Void close() This method close the stream,flushing it first. 2 Void flush() This method flushes the stream. 3 Int read() This method returns the name of the character encoding Being used by this stream. 4 Void write(char[] cbuf,int off,int len) This method writes a portion of an array of characters. 5 void write(int c) This method writes a single character. void write(string str,int off,int len) This method writes a portion of a string. 6
  • 10. Filereader  This class inherits from the InputStreamReader class. FileReader is used for reading streams of characters.  This class has several constructors to create required objects. Below given are the list of constructors provided by the FileReader class. • Constructors: S.N. Constructor & Description 1 FileReader(File file) This constructor creates a new FileReader, given the File to read from. 2 FileReader(FileDescriptor fd) This constructor creates a new FileReader, given the FileDescriptor to read from. 3 FileReader(String fileName) This constructor creates a new FileReader, given the name of the file to read from.
  • 11. File Writer  This class inherits from the OutputStreamWriter class. The class is used for writing streams of characters.  This class has serveral constructors to create required objects. Below given is the list of them. • Constructors: S.N. Constructor & Description 1 FileWriter(File file) This constructor creates a new FileWriter, given a File object. 2 FileWriter(File file, Boolean append) This constructor creates a FileWriter object given a file object. With a Boolean Indicating whether or not to append the data written. 3 FileReader(FileDescriptor fd) This constructor creates a FileWriter object associated with the given file descriptor 4 FileWriter(string fileName) This constructor creates a FileWriter object, given a file name. 5 FileWriter(string filename, Boolean append) This constructor creates a FileWriter object given a file name with a Boolean indicating whether or not to append the data written.
  • 12. • Methods: S.N. Method with Desription 1 Public Void write(int c) throws ioException Write a single character. 2 Public Void write(char [] c,int offset,int len) Write a portion of an array of characters starting from offset and with a length of len 3 Public Void write(String s,int off,int len) Write a portion of a String starting from offset and with a length of len