Reading from a file

Introduction

Similar to writing to files we can also read from a file. This is done as follows:

try {
    BufferedReader in = new BufferedReader(new FileReader("infilename"));
    String str;
    while ((str = in.readLine()) != null) {
        process(str);
    }
    in.close();
} catch (IOException e) {
}

Please note the similarities between writing. The only difference is that here the FileReader is used in stead of the FileWriter.

Leave a Reply

Your email address will not be published. Required fields are marked *

This site uses Akismet to reduce spam. Learn how your comment data is processed.