Files in java
Click here to load reader
-
Upload
muthukumaran-subramanian -
Category
Education
-
view
33 -
download
2
description
Transcript of Files in java
File
● A collection of data or information that has a name, called the filename.
● To access File in java, the package java.io.File must be imported.
● There are many other File based classes in the java.io package which has its own purpose
The Stream Classes
The basic stream classes in java are● Byte stream classes● Character stream classes● Standard stream classes
Byte Stream classes
● Java byte streams are used to perform input and output of 8-bit bytes.
● The most frequently used byte stream classes are – FileInputStream and
– FileOutputStream.
Character stream classes
● Java Byte streams are used to perform input and output of 8-bit bytes, where as Java Character streams are used to perform input and output for 16-bit unicode.
● The most frequently used character stream classes are – FileReader and
– FileWriter.
Standard Stream
Java provides following three standard streams● Standard Input: This is used to feed the data to user's program
and usually a keyboard is used as standard input stream and represented as System.in.
● Standard Output: This is used to output the data produced by the user's program and usually a computer screen is used to standard output stream and represented as System.out.
● Standard Error: This is used to output the error data produced by the user's program and usually a computer screen is used to standard error stream and represented as System.err.
Sample program to write into file
Sample program to read from file
Sample output for read from file