0

我的虚拟文件中有一个文件。我试着这样做:

    File file = new File("invoice2.xml");
    if (file.exists()) {
    textview1.setText("file exists");
    }
    else{
    textview1.setText("file dosen't exist");
    }

这显示“文件不存在”。我正在使用 Eclipse,根据 DDMS 文件资源管理器,我的“invoice2.xml”文件位于

数据/数据/发票.digital.namespace/files/invoice2.xml

我究竟做错了什么?如何获得“文件存在”结果?谢谢你

编辑:这个工作 File file = new File(MyActivity.this.getFilesDir(), "invoice2.xml");

4

2 回答 2

3

看起来您正在尝试从根文件夹中读取。试试这个方法:

File file = new File(mContext.getFilesDir() + "invoice2.xml");
于 2012-06-02T20:21:28.610 回答
0

如果可能的话最好把它放在原始或资产或文件名中应该像这样 System.getProperty("filesDir")+File.separator+YOUR_INTERNAL_FILE_NAME

于 2012-06-02T20:17:38.323 回答