Reading files in data folder on emulated android mode
in
Android Processing
•
2 months ago
Hi folks,
I am hoping that someone can clarify how to read files from a processing project's data folder on Android. I have the following sample code:
- import java.io.BufferedReader;
- import java.io.FileReader;
- import java.io.IOException;
- void setup() {
- BufferedReader br;
- String line;
- try {
- br = new BufferedReader(new FileReader(dataPath("sample.txt")));
- while((line=br.readLine())!=null){
- System.out.println(line);
- }
- } catch (Exception e) {
- System.out.println("IOException when trying to read sample.txt:\n"+e);
- System.exit(0);
- }
- }
This works fine when running processing on desktop mode, and it successfully finds and prints out sample.txt. However, when running on the Emulator under Android mode, I get a file not found exception:
IOException when trying to read sample.txt:
java.io.FileNotFoundException: /data/data/processing.test.gpa/files/data/sample.txt (No such file or directory)
Either the problem is that dataPath() is not returning the correct path on Android mode or the files in the data folder are not being transferred correctly. The "/data/data..." part of the pathname looks unusual to me and I'll look at it a bit more later, but I thought I would post something here first. I'm using Processing 2.0.1 with the v10 Android SDK installed. Any ideas?
Thanks
Mike
1