Read file, line by line

Posted by nikola, With 0 Comments, Category: Java && Android,

Simple code to read file, line by line

File file = new File(ApplicationLocation, debitFile.toString());

//Log.e("response", "debitFile -----" + file);

try {
InputStream instream = new FileInputStream("myFile.txt");
if (instream != null) {
// prepare the file for reading
InputStreamReader inputreader = new InputStreamReader(instream);
BufferedReader buffreader = new BufferedReader(inputreader);

String line = "";

// read every line of the file into the line-variable, on line at the time
while (line != null) {
line = buffreader.readLine();
Log.e("response", "RESPONSE:" + line);
}
}

} catch (FileNotFoundException e) {
e.printStackTrace();
} catch (IOException e) {
e.printStackTrace();
}

Leave a Reply

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