Question

I'm trying to open up an xml file to parse it, but I am getting stopped trying to open the file. My code is:

        try {
            return new FileInputStream(location);
        } catch (FileNotFoundException e) {
            // TODO Auto-generated catch block
            e.printStackTrace();
            return null;
        }   

where location is a String passed into the function. Upon running my code, I get:

java.io.FileNotFoundException: /C:/Users/Seth/AndroidWorkspace/UCoupon/res/xml/information.xml (No such file or directory)

I gave the full file path, and I havn't mispelled anything. What am I doing wrong?

Was it helpful?

Solution

you can't read files on your pc from your device or emulator.

see here for an introduction to Data Storage and here for Accessing Resources (that is probably what you're interested in, as you're trying to access res/xml/)

OTHER TIPS

You are trying to load a file using the real path on your PC. Emulator knows nothing about your file system.

When you put an xml into the project folder res/xml/ you can parse it using the standar resource lookup way:

XmlResourceParser xpp = res.getXml(R.xml.myxml); where myxml is the name of your xml file without the extension

You can not access files from your host system (which seems to be Windows in your case). Copy the file to your devices/emulators SD card and read it from there - and don't forget to use the WRITE_EXTERNAL_STORAGE permission.

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top