SlideShare una empresa de Scribd logo
1 de 5
Descargar para leer sin conexión
What is Java input and output stream?
What is Java input and output stream?
Java I/O (Input and Output) is used to process the feedback and produce the
outcome based on the feedback.
Java uses the idea of circulation to make I/O function fast. The java.io package
contains all the sessions required for feedback and outcome functions.
file handling in java can be performed by java IO API.
Stream
A stream is a series of information. In Java stream is comprised of bytes. Like a
water flow stream; it is called a stream as it continues with the flow .
In java, 3 sources are created for you instantly. All these sources are connected
with system.
1) Program.out: conventional output stream
2) Program.in: conventional input stream
3) Program.err: conventional error stream
OutputStream
Java program uses an outcome circulation to write information to a location, it
may be a knowledge file,an range,peripheral system or outlet.
InputStream
Java program uses a port circulation to read information from a source, it may
be a knowledge file,an range,peripheral system or outlet.
OutputStream class
OutputStream class is a subjective category.It is the superclass of all sessions
comprising an outcome stream of bytes. An output stream allows output bytes
and delivers them to some sink.
1) public void write(int)throws IOException: current output stream will contain
byte due to this code
2) public void write(byte[])throws IOException: current output stream will
contain an array of byte due to this code
3) public void flush()throws IOException: clears out the current output stream
4) public void close()throws IOException: closure of the current output stream
InputStream class
InputStream class is an subjective category. It is the superclass of all sessions
comprising a port stream of bytes.
1) public abstract int read()throws IOException: returns -1 at the end of the file
and it reads the next byte of data from the input stream.
2) public int available()throws IOException: number of readable bytes from
the current input stream can be estimated
3) public void close()throws IOException: closure of the current input stream
Java File Output Stream class
Java File Output Stream is an outcome flow for composing information to a data
file.
If you have to create basic principles then use FileOutputStream.Instead, for
character-oriented information, choose FileWriter.But you can create byte-
oriented as well as character-oriented information.
Example of Java FileOutputStream class
1. import java.io.*;
2. class Test{
3. public static void main(String args[]){
4. try{
5. FileOutputstream fout=new FileOutputStream(“abc.txt”);
6. String s=”Sachin Tendulkar is my favourite player”;
7. byte b[]=s.getBytes();//converting string into byte array
8. fout.write(b);
9. fout.close();
10. System.out.println(“success…”);
11. }catch(Exception e){system.out.println(e);}
12. }
13.}
Java File Input Stream class
Java File Input Stream category acquires feedback bytes from a data file.It is
used for studying sources of raw bytes such as picture information. For
studying sources of figures, consider using FileReader.
It should be used to study byte-oriented information for example to read
picture, sound, movie etc.
Example of FileInputStream class
1. import java.io.*;
2. class SimpleRead{
3. public static void main(String args[]){
4. try{
5. FileInputStream fin=new FileInputStream(“abc.txt”);
6. int i=0;
7. while((i=fin.read())!=-1){
8. System.out.println((char)i);
9. }
10. fin.close();
11. }catch(Exception e){system.out.println(e);}
12. }
13.}
Example of Reading the information of current Java information file and
writing it into another file
We can read the information of information file using the File Input Stream class
whether it is Java information file, image information file, video information file
etc. In this example, we are reading the information of C.java information file
and writing it into another information file M.java.
import java.io.*;
1. class C{
2. public static void main(String args[])throws Exception{
3. FileInputStream fin=new FileInputStream(“C.java”);
4. FileOutputStream fout=new FileOutputStream(“M.java”);
5. int i=0;
6. while((i=fin.read())!=-1){
7. fout.write((byte)i);
8. }
9. fin.close();
10.}
11.}
You can join the training institute in Java to make your profession in this
field.
Java-Reviews of CRB Solutions is sufficient to make you consider and take up
a career in this field.

Más contenido relacionado

La actualidad más candente

IO In Java
IO In JavaIO In Java
IO In Java
parag
 
Character stream classes introd .51
Character stream classes introd  .51Character stream classes introd  .51
Character stream classes introd .51
myrajendra
 
Various io stream classes .47
Various io stream classes .47Various io stream classes .47
Various io stream classes .47
myrajendra
 
Chapter 10.3
Chapter 10.3Chapter 10.3
Chapter 10.3
sotlsoc
 
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
phanleson
 

La actualidad más candente (20)

Java stream
Java streamJava stream
Java stream
 
Java I/o streams
Java I/o streamsJava I/o streams
Java I/o streams
 
CORE JAVA
CORE JAVACORE JAVA
CORE JAVA
 
Java
JavaJava
Java
 
Handling I/O in Java
Handling I/O in JavaHandling I/O in Java
Handling I/O in Java
 
IO In Java
IO In JavaIO In Java
IO In Java
 
CORE JAVA-1
CORE JAVA-1CORE JAVA-1
CORE JAVA-1
 
Character stream classes introd .51
Character stream classes introd  .51Character stream classes introd  .51
Character stream classes introd .51
 
Nhap xuat trong java
Nhap xuat trong javaNhap xuat trong java
Nhap xuat trong java
 
File Input & Output
File Input & OutputFile Input & Output
File Input & Output
 
Java I/O
Java I/OJava I/O
Java I/O
 
Various io stream classes .47
Various io stream classes .47Various io stream classes .47
Various io stream classes .47
 
Chapter 10.3
Chapter 10.3Chapter 10.3
Chapter 10.3
 
Chapter 12 - File Input and Output
Chapter 12 - File Input and OutputChapter 12 - File Input and Output
Chapter 12 - File Input and Output
 
Oodp mod4
Oodp mod4Oodp mod4
Oodp mod4
 
Java program file I/O
Java program file I/OJava program file I/O
Java program file I/O
 
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
 
Java Input Output and File Handling
Java Input Output and File HandlingJava Input Output and File Handling
Java Input Output and File Handling
 
[Java] #7 - Input & Output Stream
[Java] #7 - Input & Output Stream[Java] #7 - Input & Output Stream
[Java] #7 - Input & Output Stream
 
File handling
File handlingFile handling
File handling
 

Similar a What is java input and output stream?

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
SakkaravarthiS1
 
H U F F M A N Algorithm Class
H U F F M A N Algorithm ClassH U F F M A N Algorithm Class
H U F F M A N Algorithm Class
Jade Danial
 
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
RathanMB
 
Ppl for students unit 4 and 5
Ppl for students unit 4 and 5Ppl for students unit 4 and 5
Ppl for students unit 4 and 5
Akshay Nagpurkar
 

Similar a What is java input and output stream? (20)

File Input and output.pptx
File Input  and output.pptxFile Input  and output.pptx
File Input and output.pptx
 
Input output files in java
Input output files in javaInput output files in java
Input output files in java
 
Java - File Input Output Concepts
Java - File Input Output ConceptsJava - File Input Output Concepts
Java - File Input Output Concepts
 
File Handling.pptx
File Handling.pptxFile Handling.pptx
File Handling.pptx
 
File Handling in Java.pdf
File Handling in Java.pdfFile Handling in Java.pdf
File Handling in Java.pdf
 
Unit IV Notes.docx
Unit IV Notes.docxUnit IV Notes.docx
Unit IV Notes.docx
 
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
 
H U F F M A N Algorithm Class
H U F F M A N Algorithm ClassH U F F M A N Algorithm Class
H U F F M A N Algorithm Class
 
Input/Output Exploring java.io
Input/Output Exploring java.ioInput/Output Exploring java.io
Input/Output Exploring java.io
 
1.26 File Input-Output in JAVA.pptx
1.26 File Input-Output in JAVA.pptx1.26 File Input-Output in JAVA.pptx
1.26 File Input-Output in JAVA.pptx
 
Iostreams
IostreamsIostreams
Iostreams
 
Io Streams
Io StreamsIo Streams
Io Streams
 
Basic i/o & file handling in java
Basic i/o & file handling in javaBasic i/o & file handling in java
Basic i/o & file handling in java
 
IO Streams, Serialization, de-serialization, autoboxing
IO Streams, Serialization, de-serialization, autoboxingIO Streams, Serialization, de-serialization, autoboxing
IO Streams, Serialization, de-serialization, autoboxing
 
Java Day-6
Java Day-6Java Day-6
Java Day-6
 
Buffer and scanner
Buffer and scannerBuffer and scanner
Buffer and scanner
 
JAVA
JAVAJAVA
JAVA
 
Unit No 5 Files and Database Connectivity.pptx
Unit No 5 Files and Database Connectivity.pptxUnit No 5 Files and Database Connectivity.pptx
Unit No 5 Files and Database Connectivity.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
 
Ppl for students unit 4 and 5
Ppl for students unit 4 and 5Ppl for students unit 4 and 5
Ppl for students unit 4 and 5
 

Último

The basics of sentences session 3pptx.pptx
The basics of sentences session 3pptx.pptxThe basics of sentences session 3pptx.pptx
The basics of sentences session 3pptx.pptx
heathfieldcps1
 
Salient Features of India constitution especially power and functions
Salient Features of India constitution especially power and functionsSalient Features of India constitution especially power and functions
Salient Features of India constitution especially power and functions
KarakKing
 

Último (20)

Google Gemini An AI Revolution in Education.pptx
Google Gemini An AI Revolution in Education.pptxGoogle Gemini An AI Revolution in Education.pptx
Google Gemini An AI Revolution in Education.pptx
 
Single or Multiple melodic lines structure
Single or Multiple melodic lines structureSingle or Multiple melodic lines structure
Single or Multiple melodic lines structure
 
How to Add New Custom Addons Path in Odoo 17
How to Add New Custom Addons Path in Odoo 17How to Add New Custom Addons Path in Odoo 17
How to Add New Custom Addons Path in Odoo 17
 
TỔNG ÔN TẬP THI VÀO LỚP 10 MÔN TIẾNG ANH NĂM HỌC 2023 - 2024 CÓ ĐÁP ÁN (NGỮ Â...
TỔNG ÔN TẬP THI VÀO LỚP 10 MÔN TIẾNG ANH NĂM HỌC 2023 - 2024 CÓ ĐÁP ÁN (NGỮ Â...TỔNG ÔN TẬP THI VÀO LỚP 10 MÔN TIẾNG ANH NĂM HỌC 2023 - 2024 CÓ ĐÁP ÁN (NGỮ Â...
TỔNG ÔN TẬP THI VÀO LỚP 10 MÔN TIẾNG ANH NĂM HỌC 2023 - 2024 CÓ ĐÁP ÁN (NGỮ Â...
 
Accessible Digital Futures project (20/03/2024)
Accessible Digital Futures project (20/03/2024)Accessible Digital Futures project (20/03/2024)
Accessible Digital Futures project (20/03/2024)
 
How to Manage Global Discount in Odoo 17 POS
How to Manage Global Discount in Odoo 17 POSHow to Manage Global Discount in Odoo 17 POS
How to Manage Global Discount in Odoo 17 POS
 
Graduate Outcomes Presentation Slides - English
Graduate Outcomes Presentation Slides - EnglishGraduate Outcomes Presentation Slides - English
Graduate Outcomes Presentation Slides - English
 
The basics of sentences session 3pptx.pptx
The basics of sentences session 3pptx.pptxThe basics of sentences session 3pptx.pptx
The basics of sentences session 3pptx.pptx
 
Kodo Millet PPT made by Ghanshyam bairwa college of Agriculture kumher bhara...
Kodo Millet  PPT made by Ghanshyam bairwa college of Agriculture kumher bhara...Kodo Millet  PPT made by Ghanshyam bairwa college of Agriculture kumher bhara...
Kodo Millet PPT made by Ghanshyam bairwa college of Agriculture kumher bhara...
 
Unit 3 Emotional Intelligence and Spiritual Intelligence.pdf
Unit 3 Emotional Intelligence and Spiritual Intelligence.pdfUnit 3 Emotional Intelligence and Spiritual Intelligence.pdf
Unit 3 Emotional Intelligence and Spiritual Intelligence.pdf
 
How to setup Pycharm environment for Odoo 17.pptx
How to setup Pycharm environment for Odoo 17.pptxHow to setup Pycharm environment for Odoo 17.pptx
How to setup Pycharm environment for Odoo 17.pptx
 
Wellbeing inclusion and digital dystopias.pptx
Wellbeing inclusion and digital dystopias.pptxWellbeing inclusion and digital dystopias.pptx
Wellbeing inclusion and digital dystopias.pptx
 
Basic Civil Engineering first year Notes- Chapter 4 Building.pptx
Basic Civil Engineering first year Notes- Chapter 4 Building.pptxBasic Civil Engineering first year Notes- Chapter 4 Building.pptx
Basic Civil Engineering first year Notes- Chapter 4 Building.pptx
 
Salient Features of India constitution especially power and functions
Salient Features of India constitution especially power and functionsSalient Features of India constitution especially power and functions
Salient Features of India constitution especially power and functions
 
General Principles of Intellectual Property: Concepts of Intellectual Proper...
General Principles of Intellectual Property: Concepts of Intellectual  Proper...General Principles of Intellectual Property: Concepts of Intellectual  Proper...
General Principles of Intellectual Property: Concepts of Intellectual Proper...
 
How to Give a Domain for a Field in Odoo 17
How to Give a Domain for a Field in Odoo 17How to Give a Domain for a Field in Odoo 17
How to Give a Domain for a Field in Odoo 17
 
Plant propagation: Sexual and Asexual propapagation.pptx
Plant propagation: Sexual and Asexual propapagation.pptxPlant propagation: Sexual and Asexual propapagation.pptx
Plant propagation: Sexual and Asexual propapagation.pptx
 
Interdisciplinary_Insights_Data_Collection_Methods.pptx
Interdisciplinary_Insights_Data_Collection_Methods.pptxInterdisciplinary_Insights_Data_Collection_Methods.pptx
Interdisciplinary_Insights_Data_Collection_Methods.pptx
 
Holdier Curriculum Vitae (April 2024).pdf
Holdier Curriculum Vitae (April 2024).pdfHoldier Curriculum Vitae (April 2024).pdf
Holdier Curriculum Vitae (April 2024).pdf
 
HMCS Max Bernays Pre-Deployment Brief (May 2024).pptx
HMCS Max Bernays Pre-Deployment Brief (May 2024).pptxHMCS Max Bernays Pre-Deployment Brief (May 2024).pptx
HMCS Max Bernays Pre-Deployment Brief (May 2024).pptx
 

What is java input and output stream?

  • 1. What is Java input and output stream? What is Java input and output stream? Java I/O (Input and Output) is used to process the feedback and produce the outcome based on the feedback. Java uses the idea of circulation to make I/O function fast. The java.io package contains all the sessions required for feedback and outcome functions. file handling in java can be performed by java IO API. Stream A stream is a series of information. In Java stream is comprised of bytes. Like a water flow stream; it is called a stream as it continues with the flow . In java, 3 sources are created for you instantly. All these sources are connected with system. 1) Program.out: conventional output stream 2) Program.in: conventional input stream 3) Program.err: conventional error stream OutputStream Java program uses an outcome circulation to write information to a location, it may be a knowledge file,an range,peripheral system or outlet. InputStream Java program uses a port circulation to read information from a source, it may be a knowledge file,an range,peripheral system or outlet.
  • 2. OutputStream class OutputStream class is a subjective category.It is the superclass of all sessions comprising an outcome stream of bytes. An output stream allows output bytes and delivers them to some sink. 1) public void write(int)throws IOException: current output stream will contain byte due to this code 2) public void write(byte[])throws IOException: current output stream will contain an array of byte due to this code 3) public void flush()throws IOException: clears out the current output stream 4) public void close()throws IOException: closure of the current output stream InputStream class InputStream class is an subjective category. It is the superclass of all sessions comprising a port stream of bytes. 1) public abstract int read()throws IOException: returns -1 at the end of the file and it reads the next byte of data from the input stream. 2) public int available()throws IOException: number of readable bytes from the current input stream can be estimated 3) public void close()throws IOException: closure of the current input stream Java File Output Stream class Java File Output Stream is an outcome flow for composing information to a data file. If you have to create basic principles then use FileOutputStream.Instead, for character-oriented information, choose FileWriter.But you can create byte- oriented as well as character-oriented information.
  • 3. Example of Java FileOutputStream class 1. import java.io.*; 2. class Test{ 3. public static void main(String args[]){ 4. try{ 5. FileOutputstream fout=new FileOutputStream(“abc.txt”); 6. String s=”Sachin Tendulkar is my favourite player”; 7. byte b[]=s.getBytes();//converting string into byte array 8. fout.write(b); 9. fout.close(); 10. System.out.println(“success…”); 11. }catch(Exception e){system.out.println(e);} 12. } 13.} Java File Input Stream class Java File Input Stream category acquires feedback bytes from a data file.It is used for studying sources of raw bytes such as picture information. For studying sources of figures, consider using FileReader. It should be used to study byte-oriented information for example to read
  • 4. picture, sound, movie etc. Example of FileInputStream class 1. import java.io.*; 2. class SimpleRead{ 3. public static void main(String args[]){ 4. try{ 5. FileInputStream fin=new FileInputStream(“abc.txt”); 6. int i=0; 7. while((i=fin.read())!=-1){ 8. System.out.println((char)i); 9. } 10. fin.close(); 11. }catch(Exception e){system.out.println(e);} 12. } 13.} Example of Reading the information of current Java information file and writing it into another file We can read the information of information file using the File Input Stream class
  • 5. whether it is Java information file, image information file, video information file etc. In this example, we are reading the information of C.java information file and writing it into another information file M.java. import java.io.*; 1. class C{ 2. public static void main(String args[])throws Exception{ 3. FileInputStream fin=new FileInputStream(“C.java”); 4. FileOutputStream fout=new FileOutputStream(“M.java”); 5. int i=0; 6. while((i=fin.read())!=-1){ 7. fout.write((byte)i); 8. } 9. fin.close(); 10.} 11.} You can join the training institute in Java to make your profession in this field. Java-Reviews of CRB Solutions is sufficient to make you consider and take up a career in this field.