In this tutorials we are going to see how to read file using BufferedInputStream.
- Create project called JavaMisc.
- Create package called com.javatutorialscorner.io
- Create java class called FileReaderExample under com.javatutorialscorner.io package.
FileReaderExample.java
package com.javatutorialscorner.io;
import java.io.BufferedInputStream;
import java.io.DataInputStream;
import java.io.File;
import java.io.FileInputStream;
import java.io.IOException;
public class FileReaderExample {
public static void main(String[] args) {
File file = null;
FileInputStream fins = null;
BufferedInputStream bins = null;
DataInputStream din = null;
file = new File("C:\\jtc\\javatutorialscorner.txt");
try {
fins = new FileInputStream(file);
bins = new BufferedInputStream(fins);
din = new DataInputStream(bins);
while (din.available() != 0) {
System.out.println(din.readLine());
}
} catch (IOException e) {
// TODO Auto-generated catch block
e.printStackTrace();
} finally {
try {
fins.close();
bins.close();
din.close();
} catch (IOException e) {
// TODO Auto-generated catch block
e.printStackTrace();
}
}
}
}
Now run the program see the following output in console.
this is test file created by java tutorials corner
This content read from input file
0 comments:
Post a Comment