I've been experimenting with an application that reads a text file containing a dictionary of words. When I sign and publish this app, I want to include the text file in the package. At the moment, I keep the text file in the /data/app-private directory. On the emulator, I test this by first copying the text file to this directory using eclipse's DDMS perspective, and it works.
When I try to do the same on the G1 phone, I cannot copy the text file to the /data/app-private directory. Browsing the G1's file system using eclipse, I notice that there is a /data directory, but is empty. It seems that this is a read-only file system.
Q1: When preparing the package to install on the phone, how do I specify that the text file is also a part of the package? If the text file is part of the package, how do I specify its location? At the moment, my code specifies a hard-coded location like this:
- Code: Select all
String fileName = "file.txt";
String dirName = "/data/app-private";
File filePath = new File( dirName, fileName);
BufferedReader input = new BufferedReader(new FileReader(aFileName));
try
{
// Loop to count lines in the file
while( input.readLine() != null )
{
i++;
}
}
Q2: I suppose I should avoid hard-coding the file's location. I read earlier in this thread that I should use the activity method openFileInput(). Do I need to specify the file's location in this case?
- Code: Select all
FileInputStream stream = openFileInput("file.txt");
InputStreamReader osw = new InputStreamReader(stream);
Thanks again for the great site. I read earlier that you were studying for exams. How do you find the time?
Many thanks,
Paul
Can someone help?
Paul



