Files And Input Output(I/O) Stream in Java Very Short And Important Notes
Input and output(I/O) are the most commonly used operations in any program.Reading data from the keyboard and writing data on the monitor form the basic input and output operation.
Java uses streams to handle data input and output.Input streams act as sources of data and output streams act as destinations of data.The java.io package defines various classes and methods for reading and writing files and handling data streams.
Java i/o stream
Stream is a logical connection between java application and file.
Stream is nothing but a byte of data.There are three i/o stream
System.in —> Used to read the data from the keyboard
System.out —> Used to display the data on screen
System.err —> Display the error message
Every class will be available in packages. so we have to import
the package before using those classes in our program
.All these i/o streams are available in the java.io packageOutput functions
Different functions available in output stream, some functions are given below
System.out.print() —> Everything will be printed in a single line
Ex:- System.out.print(“welcome”);
System.out.print(“java”);
Output is —> welcome java
System.out.println() —> The output will be printed multiple line
Ex:- System.out.println(“welcome”);
System.out.print(“welcome”);
Output is —> welcome
Java
there are two classes read the data from keyboard
at the runtime
Scanner class —> read the data from keyboard This class available in util package
BufferedReader class —> in the BufferedReader to the help of
InputStreamReader and Filereader(read the data from either keyboard or existing file)
This class available in io package
In order to implement this scanner class import the util package
Scanner class
a class consists of variables and methods.you can implement the variables and methods by means of object creation in a particular class.
Few methods in scanner class
nextLine() —> read string
nextInt() —> read integer
nextFloat() —> read float
nextDouble() —> read double
Comments
Post a Comment