Reading Text Files using AIDE on My Tablet

  • Replies:0
Oscar Bastidas
  • Forum posts: 1

Jan 11, 2018, 12:03:39 AM via Website

Hello,

I am trying to read a text file and then print out the lines to my output screen using AIDE on my tablet, but it isn't working.

Would someone please help me out?

My code is:

import java.io.*;
//import java.nio.file.Files;

public class Reader {
public static void main(String [] args) {

    // The name of the file to open.
    String fileName = "temp.txt";

    // This will reference one line at a time
    String line = null;

    try {

/* Specify where the file is and then open it
FileInputStream instream = openFileInput("E:\test\src\com\test\mani.txt");

InputStreamReader inputStreamReader = new InputStreamReader(instream);
BufferedReader bufferedReader = new BufferedReader(inputStreamReader); */

        // FileReader reads text files in the default encoding.
        FileReader fileReader =  new FileReader("./temp.txt");

        // Always wrap FileReader in BufferedReader.
        BufferedReader bufferedReader = new BufferedReader(fileReader);

        /* THIS SECTION TO BE MODIFIED TO CONDITIONALLY PRINT EACH SNAPSHOT */

while((line = bufferedReader.readLine()) != null) {
System.out.println(line);
}

        // Always close files.
        bufferedReader.close();         
    }
    catch(FileNotFoundException ex) {
        System.out.println(
            "Unable to open file '" + 
            fileName + "'");                
    }
    catch(IOException ex) {
        System.out.println(
            "Error reading file '" 
            + fileName + "'");                  
        // Or we could just do this: 
        // ex.printStackTrace();
    }
}

}

Thanks.

Reply