Warning: file_get_contents(/data/phpspider/zhask/data//catemap/3/android/219.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
找不到Android文件路径_Android - Fatal编程技术网

找不到Android文件路径

找不到Android文件路径,android,Android,我正在尝试做XML解析程序。 我还对XML文件使用了FileInputStream。 我将XML文件放在android的资产文件夹META-INF文件夹下。 文件名是“container.XML” 这是我的XML解析代码 public void parseXMLinfoBook() throws FileNotFoundException, ParserConfigurationException, SAXException{ FileInputStream in = new

我正在尝试做XML解析程序。 我还对XML文件使用了FileInputStream。 我将XML文件放在android的资产文件夹META-INF文件夹下。 文件名是“container.XML”

这是我的XML解析代码

 public void parseXMLinfoBook() throws FileNotFoundException, ParserConfigurationException, SAXException{

        FileInputStream in = new FileInputStream("file:///android_asset/META-INF/container.xml");

        StringBuffer inLine = new StringBuffer();
        InputStreamReader isr = new InputStreamReader(in);

        BufferedReader inRd = new BufferedReader(isr);

        SAXParserFactory spf=SAXParserFactory.newInstance();
        SAXParser spr=spf.newSAXParser();
        XMLReader xmlreader = spr.getXMLReader();

        XmlHandler xmlhe=new XmlHandler();
        xmlreader.setContentHandler(xmlhe);

        }
这是Button.SetonClick代码

public void onClick(View v) {
                // TODO Auto-generated method stub
                try {
                    parseXMLinfoBook();
                } catch (FileNotFoundException e) {
                    // TODO Auto-generated catch block
                    e.printStackTrace();
                    tv.setText("ErrorPath "+e.getMessage());
                } catch (ParserConfigurationException e) {
                    // TODO Auto-generated catch block
                    e.printStackTrace();
                } catch (SAXException e) {
                    // TODO Auto-generated catch block
                    e.printStackTrace();
                }
            }
        });
我只收到一条错误信息。
希望有帮助

我假设您已将container.xml文件放在apk包中应用程序的资产目录中

要打开android应用程序的/assets目录中的文件,您需要一个。在上下文对象上可用,因此可用于您的活动或服务

AssetManager mgr = getContext().getAssets();
InputStream in = mgr.open("META-INF/container.xml");
InputStreamReader isr = new InputStreamReader(in);
//... Rest of the code

您看到了什么错误消息?