SlideShare a Scribd company logo
1 of 28
Using I/O
• Java program performs I/O through
streams.
• A stream is an abstraction that either
produces or consumes information.
• A stream is linked to physical device by
java I/O system.
• Java implements streams within class
hierarchies defined in the java.io package.
Byte streams and character
streams
• Java defines two types of streams i.e. byte
streams and character stream
• Byte streams handles input and output of
bytes. Eg: used when reading or writing
binary data.
• Character stream handles input and
output of character.
• Character streams are efficient than byte
streams.
Byte stream classes
• Defined by two class hierarchies
• Top level classes : InputStream and
OutputStream
• InputStream defines the charecterstics
common to byte input streams.
• OutputStream defines the charecterstics
common to byte output streams.
Java I/O – InputStreams
Java I/O – OutputStreams
Byte stream classes
• BufferedInputStream-
• BufferedOutputStream-
• ByteArrayInputStream- input stream that
reads from a byte array
• ByteArrayOutputStream-Output stream
that writes a byte array
• DataInputStream- an input stream that
contains methods for reading the java
standard data type.
• DataOutputStream- an Output stream that
contains methods for writing the java
standard data type.
• FileInputStream-Input stream that reads a
file
• FileOutputStream-Output stream that
writes a file
• FilterInputStream- implements InputStream
• FilterOutputStream- implements OutputStream
• InputStream- abstract class that describes
stream input
• ObjectInputStream- input stream for objects
• ObjectOutputStream- output stream for objects
• OutputStream - abstract class that describes
stream output
• PipedInputStream- Input pipe
• PipedOutputStream- Output pipe
• PrintStream –Output stream that contains print()
and println()
• PushbackInputStream – Input stream that allows
bytes to be returned to the stream.
• SequenceInputStream- input stream that is a
combination of two or more input streams that
will read sequentially one after the other.
Character stream classes
• Defined using two class heirachies topped
by two abstract classes :
• Reader and writer
• Reader is used for input
• Writer is used for output
Java I/O – Readers
Java I/O – Writers
• BufferedReader- buffered input character
stream
• BufferedWriter- Buffered output character
stream
• CharArrayReader- Input Stream that reads
character array
• CharArrayWriter- Output Stream that
writes character array
• FileReader- Input stream that reads a file
• FileWriter- Output stream that writes a file
• FilterReader- filtered reader
• FilterWriter- filtered writer
• InputStreamReader- Input stream that
translates bytes to charecters
• LineNumberReader- Input stream that
counts line number.
• OutputSreamWriter- Output stream that
translates character to bytes
• PipedReader- input pipe
• PipedWriter- output pipe
• PrintWriter- Output stream that contains println()
and print()
• PushbackReader- Input stream that allows
charecters to be returned to input stream
• Reader- Abstract class that decribes character
stream input.
• StringReader- Input stream that reads
from a string
• StringWriter- Output stream that writes to
a string
• Writer- Abstract class that describes
character stream output.
The Predefined Streams
• Java automatically imports a package
called java.lang package
• It defines a class called System.
• It contains three predefined stream
variables called in , out and err
• These fields are defined as public, final
and static within System
• Means that they can be used by any other
part of the program
• System.out refers to standard output
stream by default it is console.
• System.in refers to standard input by
default keyboard
• System.err refers to error stream, by
default it is console.
• System.in is an object of InputStream
• System.out and System.err are objects of
type PrintStream
Methods defined by
InputStream
Method Description
int avaiable() Returns the number of bytes of input currently
available for reading
void close() Close the input source
void mark(int numbytes) Places a mark at the current point in the input stream
that will remain valid until numBytes bytes are read.
boolean
marksupported()
Returns true if mark() / reset() are supported by the
invoking stream.
int read() Returns an integer representation of the next
available byte of input.
-1 is returned when end of the stream is
encountered.
int read(byte buffer[]) Attempts to read up to buffer.length bytes into buffer
and returns the actual number of bytes that were
successfully read
int read(byte buffer[],int
offset,int numbytes)
Attempts to read the
numBytes bytes into buffer
starting at buffer[offset],
returning the number of
bytes successfully read.
void reset() Resets the input pointer to
the previously set mark
long skip(long
numbytes)
Ignores numBytes bytes of
input, returning the number
of bytes actually ignored.
Methods of OutputStream
Method Desccription
void close() Closes the output stream
void flush() Causes an output that has been buffered
to be sent to its destination
void write(int b ) Writes a single byte to an output stream
void write(byte
buffer[])
Writes a complete array of bytes to an
output stream
void write(byte
buffer[],int
offset,int
numBytes)
Writes a subrange of numBytes from
array buffer beginning at buffer[offset]
Reading Console Input
• Byte or character oriented streams
• Preferred method to read console input is
to use a character oriented stream
• Reason
– makes program easier to internationalize
– easier to maintain.
• System.in is an instance of InputStream
• InputStream defines only one method called read()
which reads byte
• Three versions of read() exists
• int read() throws IOException
• int read(byte data[])throws IOException
• int read(byte data[], int start,int max) throws IOException
• Reading from System.in,pressing Enter generates end of
stream condition
• int read() throws IOException
– Reads a single character from keyboard, returns -1 if it reaches
end of stream
• int read(byte data[])throws IOException
– Reads bytes from input stream and puts them into data until
either array is full , the end of stream is encountered or error
occurs.
• int read(byte data[], int start,int max) throws IOException
– Reads input into data beginning at the location specified by start,
upto max bytes are stored.
– It returns number of byte read or -1 when end of stream is
reached.
import java.io.*;
class ReadBytes{
public static void main(String args[]) throws IOException{
byte data[]=new byte[10];
System.out.println("Enter the charecters:");
System.in.read(data);
System.out.println("You entered:");
for(int i=0;i<=data.length;i++)
System.out.println((char)data[i]);
}//end of main
}//end of class
Writing console output
• print() and println() are used for writing to console
• Defined in PrintStream class
• PrintStream is an output stream derived from
OutputStream it also implements the low-level method
called write()
• void write(int byteVal);
• This method writes the byte specified by byteval to the
file
• There are two more functions, printf and format which
allows us to write a formatted output into the console.
class WriteDemo{
public static void main(String args[])
{
int b;
b='X';
System.out.write(b);
System.out.write('n');
}//end of main
}//end of class

More Related Content

What's hot

Character stream classes introd .51
Character stream classes introd  .51Character stream classes introd  .51
Character stream classes introd .51myrajendra
 
Understanding java streams
Understanding java streamsUnderstanding java streams
Understanding java streamsShahjahan Samoon
 
IO In Java
IO In JavaIO In Java
IO In Javaparag
 
Buffer and scanner
Buffer and scannerBuffer and scanner
Buffer and scannerArif Ullah
 
Java Course 8: I/O, Files and Streams
Java Course 8: I/O, Files and StreamsJava Course 8: I/O, Files and Streams
Java Course 8: I/O, Files and StreamsAnton Keks
 
Java Input Output (java.io.*)
Java Input Output (java.io.*)Java Input Output (java.io.*)
Java Input Output (java.io.*)Om Ganesh
 
Files & IO in Java
Files & IO in JavaFiles & IO in Java
Files & IO in JavaCIB Egypt
 
Java Input and Output
Java Input and OutputJava Input and Output
Java Input and OutputDucat India
 
Java IO Package and Streams
Java IO Package and StreamsJava IO Package and Streams
Java IO Package and Streamsbabak danyal
 
java.io - streams and files
java.io - streams and filesjava.io - streams and files
java.io - streams and filesMarcello Thiry
 
Nhap xuat trong java
Nhap xuat trong javaNhap xuat trong java
Nhap xuat trong javatuhn
 

What's hot (20)

Oodp mod4
Oodp mod4Oodp mod4
Oodp mod4
 
Character stream classes introd .51
Character stream classes introd  .51Character stream classes introd  .51
Character stream classes introd .51
 
Understanding java streams
Understanding java streamsUnderstanding java streams
Understanding java streams
 
IO In Java
IO In JavaIO In Java
IO In Java
 
Buffer and scanner
Buffer and scannerBuffer and scanner
Buffer and scanner
 
32.java input-output
32.java input-output32.java input-output
32.java input-output
 
Java Course 8: I/O, Files and Streams
Java Course 8: I/O, Files and StreamsJava Course 8: I/O, Files and Streams
Java Course 8: I/O, Files and Streams
 
Java stream
Java streamJava stream
Java stream
 
Java Input Output (java.io.*)
Java Input Output (java.io.*)Java Input Output (java.io.*)
Java Input Output (java.io.*)
 
Java IO
Java IOJava IO
Java IO
 
Handling I/O in Java
Handling I/O in JavaHandling I/O in Java
Handling I/O in Java
 
Java I/o streams
Java I/o streamsJava I/o streams
Java I/o streams
 
Files & IO in Java
Files & IO in JavaFiles & IO in Java
Files & IO in Java
 
Java Input and Output
Java Input and OutputJava Input and Output
Java Input and Output
 
Io Streams
Io StreamsIo Streams
Io Streams
 
Inputstream
InputstreamInputstream
Inputstream
 
Java
JavaJava
Java
 
Java IO Package and Streams
Java IO Package and StreamsJava IO Package and Streams
Java IO Package and Streams
 
java.io - streams and files
java.io - streams and filesjava.io - streams and files
java.io - streams and files
 
Nhap xuat trong java
Nhap xuat trong javaNhap xuat trong java
Nhap xuat trong java
 

Similar to Using Input Output

Stream In Java.pptx
Stream In Java.pptxStream In Java.pptx
Stream In Java.pptxssuser9d7049
 
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
 
UNIT4-IO,Generics,String Handling.pdf Notes
UNIT4-IO,Generics,String Handling.pdf NotesUNIT4-IO,Generics,String Handling.pdf Notes
UNIT4-IO,Generics,String Handling.pdf NotesSakkaravarthiS1
 
CHAPTER 5 mechanical engineeringasaaa.pptx
CHAPTER 5 mechanical engineeringasaaa.pptxCHAPTER 5 mechanical engineeringasaaa.pptx
CHAPTER 5 mechanical engineeringasaaa.pptxSadhilAggarwal
 
Chapter 13_m5JAVANOTESAPPLETS,INPUT.pptx
Chapter 13_m5JAVANOTESAPPLETS,INPUT.pptxChapter 13_m5JAVANOTESAPPLETS,INPUT.pptx
Chapter 13_m5JAVANOTESAPPLETS,INPUT.pptxnoonoboom
 
Java input output package
Java input output packageJava input output package
Java input output packageSujit Kumar
 
Stream Based Input Output
Stream Based Input OutputStream Based Input Output
Stream Based Input OutputBharat17485
 
inputoutputstreams-140612032817-phpapp02.pdf
inputoutputstreams-140612032817-phpapp02.pdfinputoutputstreams-140612032817-phpapp02.pdf
inputoutputstreams-140612032817-phpapp02.pdfhemanth248901
 
File Input and output.pptx
File Input  and output.pptxFile Input  and output.pptx
File Input and output.pptxcherryreddygannu
 
Java Tutorial Lab 6
Java Tutorial Lab 6Java Tutorial Lab 6
Java Tutorial Lab 6Berk Soysal
 
FILE OPERATIONS.pptx
FILE OPERATIONS.pptxFILE OPERATIONS.pptx
FILE OPERATIONS.pptxDeepasCSE
 

Similar to Using Input Output (20)

Stream In Java.pptx
Stream In Java.pptxStream In Java.pptx
Stream In Java.pptx
 
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
 
UNIT4-IO,Generics,String Handling.pdf Notes
UNIT4-IO,Generics,String Handling.pdf NotesUNIT4-IO,Generics,String Handling.pdf Notes
UNIT4-IO,Generics,String Handling.pdf Notes
 
JAVA (UNIT 3)
JAVA (UNIT 3)JAVA (UNIT 3)
JAVA (UNIT 3)
 
Unit IV Notes.docx
Unit IV Notes.docxUnit IV Notes.docx
Unit IV Notes.docx
 
Basic IO
Basic IOBasic IO
Basic IO
 
Md121 streams
Md121 streamsMd121 streams
Md121 streams
 
CHAPTER 5 mechanical engineeringasaaa.pptx
CHAPTER 5 mechanical engineeringasaaa.pptxCHAPTER 5 mechanical engineeringasaaa.pptx
CHAPTER 5 mechanical engineeringasaaa.pptx
 
Chapter 13_m5JAVANOTESAPPLETS,INPUT.pptx
Chapter 13_m5JAVANOTESAPPLETS,INPUT.pptxChapter 13_m5JAVANOTESAPPLETS,INPUT.pptx
Chapter 13_m5JAVANOTESAPPLETS,INPUT.pptx
 
Java input output package
Java input output packageJava input output package
Java input output package
 
Stream Based Input Output
Stream Based Input OutputStream Based Input Output
Stream Based Input Output
 
inputoutputstreams-140612032817-phpapp02.pdf
inputoutputstreams-140612032817-phpapp02.pdfinputoutputstreams-140612032817-phpapp02.pdf
inputoutputstreams-140612032817-phpapp02.pdf
 
Input output streams
Input output streamsInput output streams
Input output streams
 
Java Day-6
Java Day-6Java Day-6
Java Day-6
 
IOStream.pptx
IOStream.pptxIOStream.pptx
IOStream.pptx
 
File Input and output.pptx
File Input  and output.pptxFile Input  and output.pptx
File Input and output.pptx
 
Streams in Java 8
Streams in Java 8Streams in Java 8
Streams in Java 8
 
Java Tutorial Lab 6
Java Tutorial Lab 6Java Tutorial Lab 6
Java Tutorial Lab 6
 
FILE OPERATIONS.pptx
FILE OPERATIONS.pptxFILE OPERATIONS.pptx
FILE OPERATIONS.pptx
 
Javaiostream
JavaiostreamJavaiostream
Javaiostream
 

More from raksharao

Unit 1-logic
Unit 1-logicUnit 1-logic
Unit 1-logicraksharao
 
Unit 1 rules of inference
Unit 1  rules of inferenceUnit 1  rules of inference
Unit 1 rules of inferenceraksharao
 
Unit 1 quantifiers
Unit 1  quantifiersUnit 1  quantifiers
Unit 1 quantifiersraksharao
 
Unit 1 introduction to proofs
Unit 1  introduction to proofsUnit 1  introduction to proofs
Unit 1 introduction to proofsraksharao
 
Unit 7 verification &amp; validation
Unit 7 verification &amp; validationUnit 7 verification &amp; validation
Unit 7 verification &amp; validationraksharao
 
Unit 6 input modeling problems
Unit 6 input modeling problemsUnit 6 input modeling problems
Unit 6 input modeling problemsraksharao
 
Unit 6 input modeling
Unit 6 input modeling Unit 6 input modeling
Unit 6 input modeling raksharao
 
Unit 5 general principles, simulation software
Unit 5 general principles, simulation softwareUnit 5 general principles, simulation software
Unit 5 general principles, simulation softwareraksharao
 
Unit 5 general principles, simulation software problems
Unit 5  general principles, simulation software problemsUnit 5  general principles, simulation software problems
Unit 5 general principles, simulation software problemsraksharao
 
Unit 4 queuing models
Unit 4 queuing modelsUnit 4 queuing models
Unit 4 queuing modelsraksharao
 
Unit 4 queuing models problems
Unit 4 queuing models problemsUnit 4 queuing models problems
Unit 4 queuing models problemsraksharao
 
Unit 3 random number generation, random-variate generation
Unit 3 random number generation, random-variate generationUnit 3 random number generation, random-variate generation
Unit 3 random number generation, random-variate generationraksharao
 
Unit 1 introduction contd
Unit 1 introduction contdUnit 1 introduction contd
Unit 1 introduction contdraksharao
 
Unit 1 introduction
Unit 1 introductionUnit 1 introduction
Unit 1 introductionraksharao
 
Module1 part2
Module1 part2Module1 part2
Module1 part2raksharao
 
Module1 Mobile Computing Architecture
Module1 Mobile Computing ArchitectureModule1 Mobile Computing Architecture
Module1 Mobile Computing Architectureraksharao
 
java-Unit4 chap2- awt controls and layout managers of applet
java-Unit4 chap2- awt controls and layout managers of appletjava-Unit4 chap2- awt controls and layout managers of applet
java-Unit4 chap2- awt controls and layout managers of appletraksharao
 
java Unit4 chapter1 applets
java Unit4 chapter1 appletsjava Unit4 chapter1 applets
java Unit4 chapter1 appletsraksharao
 
Chap3 multi threaded programming
Chap3 multi threaded programmingChap3 multi threaded programming
Chap3 multi threaded programmingraksharao
 
Java-Unit 3- Chap2 exception handling
Java-Unit 3- Chap2 exception handlingJava-Unit 3- Chap2 exception handling
Java-Unit 3- Chap2 exception handlingraksharao
 

More from raksharao (20)

Unit 1-logic
Unit 1-logicUnit 1-logic
Unit 1-logic
 
Unit 1 rules of inference
Unit 1  rules of inferenceUnit 1  rules of inference
Unit 1 rules of inference
 
Unit 1 quantifiers
Unit 1  quantifiersUnit 1  quantifiers
Unit 1 quantifiers
 
Unit 1 introduction to proofs
Unit 1  introduction to proofsUnit 1  introduction to proofs
Unit 1 introduction to proofs
 
Unit 7 verification &amp; validation
Unit 7 verification &amp; validationUnit 7 verification &amp; validation
Unit 7 verification &amp; validation
 
Unit 6 input modeling problems
Unit 6 input modeling problemsUnit 6 input modeling problems
Unit 6 input modeling problems
 
Unit 6 input modeling
Unit 6 input modeling Unit 6 input modeling
Unit 6 input modeling
 
Unit 5 general principles, simulation software
Unit 5 general principles, simulation softwareUnit 5 general principles, simulation software
Unit 5 general principles, simulation software
 
Unit 5 general principles, simulation software problems
Unit 5  general principles, simulation software problemsUnit 5  general principles, simulation software problems
Unit 5 general principles, simulation software problems
 
Unit 4 queuing models
Unit 4 queuing modelsUnit 4 queuing models
Unit 4 queuing models
 
Unit 4 queuing models problems
Unit 4 queuing models problemsUnit 4 queuing models problems
Unit 4 queuing models problems
 
Unit 3 random number generation, random-variate generation
Unit 3 random number generation, random-variate generationUnit 3 random number generation, random-variate generation
Unit 3 random number generation, random-variate generation
 
Unit 1 introduction contd
Unit 1 introduction contdUnit 1 introduction contd
Unit 1 introduction contd
 
Unit 1 introduction
Unit 1 introductionUnit 1 introduction
Unit 1 introduction
 
Module1 part2
Module1 part2Module1 part2
Module1 part2
 
Module1 Mobile Computing Architecture
Module1 Mobile Computing ArchitectureModule1 Mobile Computing Architecture
Module1 Mobile Computing Architecture
 
java-Unit4 chap2- awt controls and layout managers of applet
java-Unit4 chap2- awt controls and layout managers of appletjava-Unit4 chap2- awt controls and layout managers of applet
java-Unit4 chap2- awt controls and layout managers of applet
 
java Unit4 chapter1 applets
java Unit4 chapter1 appletsjava Unit4 chapter1 applets
java Unit4 chapter1 applets
 
Chap3 multi threaded programming
Chap3 multi threaded programmingChap3 multi threaded programming
Chap3 multi threaded programming
 
Java-Unit 3- Chap2 exception handling
Java-Unit 3- Chap2 exception handlingJava-Unit 3- Chap2 exception handling
Java-Unit 3- Chap2 exception handling
 

Recently uploaded

Online electricity billing project report..pdf
Online electricity billing project report..pdfOnline electricity billing project report..pdf
Online electricity billing project report..pdfKamal Acharya
 
Unit 4_Part 1 CSE2001 Exception Handling and Function Template and Class Temp...
Unit 4_Part 1 CSE2001 Exception Handling and Function Template and Class Temp...Unit 4_Part 1 CSE2001 Exception Handling and Function Template and Class Temp...
Unit 4_Part 1 CSE2001 Exception Handling and Function Template and Class Temp...drmkjayanthikannan
 
Unleashing the Power of the SORA AI lastest leap
Unleashing the Power of the SORA AI lastest leapUnleashing the Power of the SORA AI lastest leap
Unleashing the Power of the SORA AI lastest leapRishantSharmaFr
 
Design For Accessibility: Getting it right from the start
Design For Accessibility: Getting it right from the startDesign For Accessibility: Getting it right from the start
Design For Accessibility: Getting it right from the startQuintin Balsdon
 
Tamil Call Girls Bhayandar WhatsApp +91-9930687706, Best Service
Tamil Call Girls Bhayandar WhatsApp +91-9930687706, Best ServiceTamil Call Girls Bhayandar WhatsApp +91-9930687706, Best Service
Tamil Call Girls Bhayandar WhatsApp +91-9930687706, Best Servicemeghakumariji156
 
DC MACHINE-Motoring and generation, Armature circuit equation
DC MACHINE-Motoring and generation, Armature circuit equationDC MACHINE-Motoring and generation, Armature circuit equation
DC MACHINE-Motoring and generation, Armature circuit equationBhangaleSonal
 
Computer Lecture 01.pptxIntroduction to Computers
Computer Lecture 01.pptxIntroduction to ComputersComputer Lecture 01.pptxIntroduction to Computers
Computer Lecture 01.pptxIntroduction to ComputersMairaAshraf6
 
data_management_and _data_science_cheat_sheet.pdf
data_management_and _data_science_cheat_sheet.pdfdata_management_and _data_science_cheat_sheet.pdf
data_management_and _data_science_cheat_sheet.pdfJiananWang21
 
Employee leave management system project.
Employee leave management system project.Employee leave management system project.
Employee leave management system project.Kamal Acharya
 
Kuwait City MTP kit ((+919101817206)) Buy Abortion Pills Kuwait
Kuwait City MTP kit ((+919101817206)) Buy Abortion Pills KuwaitKuwait City MTP kit ((+919101817206)) Buy Abortion Pills Kuwait
Kuwait City MTP kit ((+919101817206)) Buy Abortion Pills Kuwaitjaanualu31
 
A CASE STUDY ON CERAMIC INDUSTRY OF BANGLADESH.pptx
A CASE STUDY ON CERAMIC INDUSTRY OF BANGLADESH.pptxA CASE STUDY ON CERAMIC INDUSTRY OF BANGLADESH.pptx
A CASE STUDY ON CERAMIC INDUSTRY OF BANGLADESH.pptxmaisarahman1
 
HOA1&2 - Module 3 - PREHISTORCI ARCHITECTURE OF KERALA.pptx
HOA1&2 - Module 3 - PREHISTORCI ARCHITECTURE OF KERALA.pptxHOA1&2 - Module 3 - PREHISTORCI ARCHITECTURE OF KERALA.pptx
HOA1&2 - Module 3 - PREHISTORCI ARCHITECTURE OF KERALA.pptxSCMS School of Architecture
 
Moment Distribution Method For Btech Civil
Moment Distribution Method For Btech CivilMoment Distribution Method For Btech Civil
Moment Distribution Method For Btech CivilVinayVitekari
 
DeepFakes presentation : brief idea of DeepFakes
DeepFakes presentation : brief idea of DeepFakesDeepFakes presentation : brief idea of DeepFakes
DeepFakes presentation : brief idea of DeepFakesMayuraD1
 
Navigating Complexity: The Role of Trusted Partners and VIAS3D in Dassault Sy...
Navigating Complexity: The Role of Trusted Partners and VIAS3D in Dassault Sy...Navigating Complexity: The Role of Trusted Partners and VIAS3D in Dassault Sy...
Navigating Complexity: The Role of Trusted Partners and VIAS3D in Dassault Sy...Arindam Chakraborty, Ph.D., P.E. (CA, TX)
 
Verification of thevenin's theorem for BEEE Lab (1).pptx
Verification of thevenin's theorem for BEEE Lab (1).pptxVerification of thevenin's theorem for BEEE Lab (1).pptx
Verification of thevenin's theorem for BEEE Lab (1).pptxchumtiyababu
 
HAND TOOLS USED AT ELECTRONICS WORK PRESENTED BY KOUSTAV SARKAR
HAND TOOLS USED AT ELECTRONICS WORK PRESENTED BY KOUSTAV SARKARHAND TOOLS USED AT ELECTRONICS WORK PRESENTED BY KOUSTAV SARKAR
HAND TOOLS USED AT ELECTRONICS WORK PRESENTED BY KOUSTAV SARKARKOUSTAV SARKAR
 
Engineering Drawing focus on projection of planes
Engineering Drawing focus on projection of planesEngineering Drawing focus on projection of planes
Engineering Drawing focus on projection of planesRAJNEESHKUMAR341697
 
Hostel management system project report..pdf
Hostel management system project report..pdfHostel management system project report..pdf
Hostel management system project report..pdfKamal Acharya
 

Recently uploaded (20)

Online electricity billing project report..pdf
Online electricity billing project report..pdfOnline electricity billing project report..pdf
Online electricity billing project report..pdf
 
Unit 4_Part 1 CSE2001 Exception Handling and Function Template and Class Temp...
Unit 4_Part 1 CSE2001 Exception Handling and Function Template and Class Temp...Unit 4_Part 1 CSE2001 Exception Handling and Function Template and Class Temp...
Unit 4_Part 1 CSE2001 Exception Handling and Function Template and Class Temp...
 
Unleashing the Power of the SORA AI lastest leap
Unleashing the Power of the SORA AI lastest leapUnleashing the Power of the SORA AI lastest leap
Unleashing the Power of the SORA AI lastest leap
 
Design For Accessibility: Getting it right from the start
Design For Accessibility: Getting it right from the startDesign For Accessibility: Getting it right from the start
Design For Accessibility: Getting it right from the start
 
Tamil Call Girls Bhayandar WhatsApp +91-9930687706, Best Service
Tamil Call Girls Bhayandar WhatsApp +91-9930687706, Best ServiceTamil Call Girls Bhayandar WhatsApp +91-9930687706, Best Service
Tamil Call Girls Bhayandar WhatsApp +91-9930687706, Best Service
 
DC MACHINE-Motoring and generation, Armature circuit equation
DC MACHINE-Motoring and generation, Armature circuit equationDC MACHINE-Motoring and generation, Armature circuit equation
DC MACHINE-Motoring and generation, Armature circuit equation
 
Computer Lecture 01.pptxIntroduction to Computers
Computer Lecture 01.pptxIntroduction to ComputersComputer Lecture 01.pptxIntroduction to Computers
Computer Lecture 01.pptxIntroduction to Computers
 
data_management_and _data_science_cheat_sheet.pdf
data_management_and _data_science_cheat_sheet.pdfdata_management_and _data_science_cheat_sheet.pdf
data_management_and _data_science_cheat_sheet.pdf
 
Employee leave management system project.
Employee leave management system project.Employee leave management system project.
Employee leave management system project.
 
FEA Based Level 3 Assessment of Deformed Tanks with Fluid Induced Loads
FEA Based Level 3 Assessment of Deformed Tanks with Fluid Induced LoadsFEA Based Level 3 Assessment of Deformed Tanks with Fluid Induced Loads
FEA Based Level 3 Assessment of Deformed Tanks with Fluid Induced Loads
 
Kuwait City MTP kit ((+919101817206)) Buy Abortion Pills Kuwait
Kuwait City MTP kit ((+919101817206)) Buy Abortion Pills KuwaitKuwait City MTP kit ((+919101817206)) Buy Abortion Pills Kuwait
Kuwait City MTP kit ((+919101817206)) Buy Abortion Pills Kuwait
 
A CASE STUDY ON CERAMIC INDUSTRY OF BANGLADESH.pptx
A CASE STUDY ON CERAMIC INDUSTRY OF BANGLADESH.pptxA CASE STUDY ON CERAMIC INDUSTRY OF BANGLADESH.pptx
A CASE STUDY ON CERAMIC INDUSTRY OF BANGLADESH.pptx
 
HOA1&2 - Module 3 - PREHISTORCI ARCHITECTURE OF KERALA.pptx
HOA1&2 - Module 3 - PREHISTORCI ARCHITECTURE OF KERALA.pptxHOA1&2 - Module 3 - PREHISTORCI ARCHITECTURE OF KERALA.pptx
HOA1&2 - Module 3 - PREHISTORCI ARCHITECTURE OF KERALA.pptx
 
Moment Distribution Method For Btech Civil
Moment Distribution Method For Btech CivilMoment Distribution Method For Btech Civil
Moment Distribution Method For Btech Civil
 
DeepFakes presentation : brief idea of DeepFakes
DeepFakes presentation : brief idea of DeepFakesDeepFakes presentation : brief idea of DeepFakes
DeepFakes presentation : brief idea of DeepFakes
 
Navigating Complexity: The Role of Trusted Partners and VIAS3D in Dassault Sy...
Navigating Complexity: The Role of Trusted Partners and VIAS3D in Dassault Sy...Navigating Complexity: The Role of Trusted Partners and VIAS3D in Dassault Sy...
Navigating Complexity: The Role of Trusted Partners and VIAS3D in Dassault Sy...
 
Verification of thevenin's theorem for BEEE Lab (1).pptx
Verification of thevenin's theorem for BEEE Lab (1).pptxVerification of thevenin's theorem for BEEE Lab (1).pptx
Verification of thevenin's theorem for BEEE Lab (1).pptx
 
HAND TOOLS USED AT ELECTRONICS WORK PRESENTED BY KOUSTAV SARKAR
HAND TOOLS USED AT ELECTRONICS WORK PRESENTED BY KOUSTAV SARKARHAND TOOLS USED AT ELECTRONICS WORK PRESENTED BY KOUSTAV SARKAR
HAND TOOLS USED AT ELECTRONICS WORK PRESENTED BY KOUSTAV SARKAR
 
Engineering Drawing focus on projection of planes
Engineering Drawing focus on projection of planesEngineering Drawing focus on projection of planes
Engineering Drawing focus on projection of planes
 
Hostel management system project report..pdf
Hostel management system project report..pdfHostel management system project report..pdf
Hostel management system project report..pdf
 

Using Input Output

  • 2. • Java program performs I/O through streams. • A stream is an abstraction that either produces or consumes information. • A stream is linked to physical device by java I/O system. • Java implements streams within class hierarchies defined in the java.io package.
  • 3. Byte streams and character streams • Java defines two types of streams i.e. byte streams and character stream • Byte streams handles input and output of bytes. Eg: used when reading or writing binary data. • Character stream handles input and output of character. • Character streams are efficient than byte streams.
  • 4. Byte stream classes • Defined by two class hierarchies • Top level classes : InputStream and OutputStream • InputStream defines the charecterstics common to byte input streams. • OutputStream defines the charecterstics common to byte output streams.
  • 5. Java I/O – InputStreams
  • 6. Java I/O – OutputStreams
  • 7. Byte stream classes • BufferedInputStream- • BufferedOutputStream- • ByteArrayInputStream- input stream that reads from a byte array • ByteArrayOutputStream-Output stream that writes a byte array • DataInputStream- an input stream that contains methods for reading the java standard data type.
  • 8. • DataOutputStream- an Output stream that contains methods for writing the java standard data type. • FileInputStream-Input stream that reads a file • FileOutputStream-Output stream that writes a file
  • 9. • FilterInputStream- implements InputStream • FilterOutputStream- implements OutputStream • InputStream- abstract class that describes stream input • ObjectInputStream- input stream for objects • ObjectOutputStream- output stream for objects • OutputStream - abstract class that describes stream output
  • 10. • PipedInputStream- Input pipe • PipedOutputStream- Output pipe • PrintStream –Output stream that contains print() and println() • PushbackInputStream – Input stream that allows bytes to be returned to the stream. • SequenceInputStream- input stream that is a combination of two or more input streams that will read sequentially one after the other.
  • 11. Character stream classes • Defined using two class heirachies topped by two abstract classes : • Reader and writer • Reader is used for input • Writer is used for output
  • 12. Java I/O – Readers
  • 13. Java I/O – Writers
  • 14. • BufferedReader- buffered input character stream • BufferedWriter- Buffered output character stream • CharArrayReader- Input Stream that reads character array • CharArrayWriter- Output Stream that writes character array
  • 15. • FileReader- Input stream that reads a file • FileWriter- Output stream that writes a file • FilterReader- filtered reader • FilterWriter- filtered writer • InputStreamReader- Input stream that translates bytes to charecters • LineNumberReader- Input stream that counts line number.
  • 16. • OutputSreamWriter- Output stream that translates character to bytes • PipedReader- input pipe • PipedWriter- output pipe • PrintWriter- Output stream that contains println() and print() • PushbackReader- Input stream that allows charecters to be returned to input stream • Reader- Abstract class that decribes character stream input.
  • 17. • StringReader- Input stream that reads from a string • StringWriter- Output stream that writes to a string • Writer- Abstract class that describes character stream output.
  • 18. The Predefined Streams • Java automatically imports a package called java.lang package • It defines a class called System. • It contains three predefined stream variables called in , out and err • These fields are defined as public, final and static within System • Means that they can be used by any other part of the program
  • 19. • System.out refers to standard output stream by default it is console. • System.in refers to standard input by default keyboard • System.err refers to error stream, by default it is console. • System.in is an object of InputStream • System.out and System.err are objects of type PrintStream
  • 20. Methods defined by InputStream Method Description int avaiable() Returns the number of bytes of input currently available for reading void close() Close the input source void mark(int numbytes) Places a mark at the current point in the input stream that will remain valid until numBytes bytes are read. boolean marksupported() Returns true if mark() / reset() are supported by the invoking stream. int read() Returns an integer representation of the next available byte of input. -1 is returned when end of the stream is encountered. int read(byte buffer[]) Attempts to read up to buffer.length bytes into buffer and returns the actual number of bytes that were successfully read
  • 21. int read(byte buffer[],int offset,int numbytes) Attempts to read the numBytes bytes into buffer starting at buffer[offset], returning the number of bytes successfully read. void reset() Resets the input pointer to the previously set mark long skip(long numbytes) Ignores numBytes bytes of input, returning the number of bytes actually ignored.
  • 22. Methods of OutputStream Method Desccription void close() Closes the output stream void flush() Causes an output that has been buffered to be sent to its destination void write(int b ) Writes a single byte to an output stream void write(byte buffer[]) Writes a complete array of bytes to an output stream void write(byte buffer[],int offset,int numBytes) Writes a subrange of numBytes from array buffer beginning at buffer[offset]
  • 23. Reading Console Input • Byte or character oriented streams • Preferred method to read console input is to use a character oriented stream • Reason – makes program easier to internationalize – easier to maintain.
  • 24. • System.in is an instance of InputStream • InputStream defines only one method called read() which reads byte • Three versions of read() exists • int read() throws IOException • int read(byte data[])throws IOException • int read(byte data[], int start,int max) throws IOException • Reading from System.in,pressing Enter generates end of stream condition
  • 25. • int read() throws IOException – Reads a single character from keyboard, returns -1 if it reaches end of stream • int read(byte data[])throws IOException – Reads bytes from input stream and puts them into data until either array is full , the end of stream is encountered or error occurs. • int read(byte data[], int start,int max) throws IOException – Reads input into data beginning at the location specified by start, upto max bytes are stored. – It returns number of byte read or -1 when end of stream is reached.
  • 26. import java.io.*; class ReadBytes{ public static void main(String args[]) throws IOException{ byte data[]=new byte[10]; System.out.println("Enter the charecters:"); System.in.read(data); System.out.println("You entered:"); for(int i=0;i<=data.length;i++) System.out.println((char)data[i]); }//end of main }//end of class
  • 27. Writing console output • print() and println() are used for writing to console • Defined in PrintStream class • PrintStream is an output stream derived from OutputStream it also implements the low-level method called write() • void write(int byteVal); • This method writes the byte specified by byteval to the file • There are two more functions, printf and format which allows us to write a formatted output into the console.
  • 28. class WriteDemo{ public static void main(String args[]) { int b; b='X'; System.out.write(b); System.out.write('n'); }//end of main }//end of class