I'm developing an app for Android, and I've run into a problem. Using the following 2 objects I have successfully written data to a file. I've checked this using the android file explorer.
FileOutputStream outFile = openFileOutput("myfile.dat", MODE_WORLD_READABLE);
OutputStreamWriter osw = new OutputStreamWriter(outFile);
File's output is as follows. Underscore represents an empty line.
1
2
3
4
5
_
Later in this code, an instance of ThingTable needs to be initialized. A filename is required for ThingTable's constructor. ThingTable goes through, and grabs the data line by line from myfile.dat. I use a Scanner variable to try to read from the file. Here is the code from the constructor. I've checked, and filename is myfile.dat
Scanner scan = new Scanner(new File("myfile.dat"));
while(scan.hasNextLine())
{
String t1 = scan.nextLine();
String t2 = scan.nextLine();
String t3 = scan.nextLine();
String t4 = scan.nextLine();
String t5 = scan.nextLine();
addItem(new ThingNode(t1, t2, t3, t4, t5));
}
scan.close();
When this code runs, I get a FileNotFound exception. Why can't this code find the file?
Sidenote: I acknowledge an error in my read function. The constructor will try to read lines that don't exist. That's not the issue here.