0

First: see my question Reading XML online and Storing It (Using Java). Read the approved answers and the comments underneath that answer.

So, what my question here is: even though I've run through the process described in the linked question, and the .xml file saves to the /res/values folder in my Android App, its not showing up at all - not when I'm running the app, nor after I close the app.

Does anyone have any ideas on how to fix this so that when I generate the file, it will be available right away, even while the app is running, to read and use?

Community
  • 1
  • 1
Mxyk
  • 10,678
  • 16
  • 57
  • 76
  • how can you write file in res/value folder in application package? – user370305 Aug 18 '11 at 18:47
  • If you look at my code in the link stated in my question, I implemented the approved answer's code and changed the file directory to "/Users/csatbu/Documents/workspace/Employee App/res/values/employeeInfo.xml", which is the directory into my app's (Employee App) /res/value folder. – Mxyk Aug 18 '11 at 18:53
  • why dnt you put the xml file in your app's data/data/file dir? – user370305 Aug 18 '11 at 19:01

2 Answers2

1

I'm not 100% sure if you're running the XML parsing in Java or actually in your Android app.

If you're running in Java, be aware that your project structure isn't live in the emulator - the .apk was packaged up and installed before running. You need to use adb to push files into the emulator (or your Android device) before your app can see the file.

If you're accessing the file in the app: If you use file access methods such as openFileOutput() it will show up in the private directory on the device, which would be /data/data//files/

However, if you're using "new File(" rather than "context.openFileOutput" then the file is wherever you put it.

ProjectJourneyman
  • 3,566
  • 1
  • 27
  • 37
1

just use this code,

FileOutputStream fOut = null;
try {
    fOut = this.openFileOutput("your xml file name.xml", MODE_PRIVATE);
    try {
        InputStream is = new FileInputStream("your source file");
        int size = is.available();
        byte[] buffer = new byte[size];
        is.read(buffer);
        is.close();
        fOut.write(buffer);
    } catch(Exception e) {
        e.printStackTrace();
    }
} catch (FileNotFoundException e) {
    e.printStackTrace();
} finally {
    try {
        fOut.close();
    } catch (IOException e) {
        e.printStackTrace();
    }
} 

and you can see your xml file at the data/data/packagename/file folder Thnx. Hope this will help you.

Yurets
  • 3,999
  • 17
  • 54
  • 74
user370305
  • 108,599
  • 23
  • 164
  • 151
  • The only thing I'm a little confused about here is what goes under "your xml file name.xml" and "your source file". If I'm pulling the xml down from a url, should I enter `http://www.....` under "your xml file name.xml"? If so, what should I put under "your source file"? – Mxyk Aug 19 '11 at 13:16
  • fOut = this.openFileOutput("your xml file name.xml", MODE_PRIVATE); your xml file name.xml is the name of file which will created at data/data/packagename/file folder means output file name. And InputStream is = new FileInputStream("your source file"); your source file means the file which you want to read from the web and write to app package. You can convert the file in inputstream then use it, or if the file is already in your device's external storage then use its file path. Sorry for let answer. – user370305 Aug 20 '11 at 10:34