java2db

How to read file using BufferedReader in java



The java.io package provides service to do all file input and file output operations.See the below example to read file using BufferedReader.

read file using BufferedReader in java Follow the steps to read file using BufferedReader class:

read file using BufferedReader in java Create a file (Example : read.txt) in any valid location (Example: C:\\Java2dbExamples\\read.txt) and ….add some text to it.

read file using BufferedReader in java In the readfileExe class , specify the location of the (read.txt) file to the File constructor.

read file using BufferedReader in java Now read file using BufferedReader  read() method.
read file using BufferedReader in java Finally close the file.

 
Note : While doing this , it throws an IOException. So handle it by throws IOException or by  using try,catch block.

read file using BufferedReader in javaExample to read file using BufferedReader :

Another example by using FileReader :

read.txt




Related Posts :
   [will not be published]



^ <