Files in java

8

Click here to load reader

description

introduction to files in java

Transcript of Files in java

Page 1: 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

Page 2: Files in java

The Stream Classes

The basic stream classes in java are● Byte stream classes● Character stream classes● Standard stream classes

Page 3: Files in java

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.

Page 4: Files in java

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.

Page 5: Files in java

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.

Page 6: Files in java

Sample program to write into file

Page 7: Files in java

Sample program to read from file

Page 8: Files in java

Sample output for read from file