Warning: file_get_contents(/data/phpspider/zhask/data//catemap/9/java/394.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
Java 如何在android项目中获取文件路径_Java_Android_Junit_Robotium - Fatal编程技术网

Java 如何在android项目中获取文件路径

Java 如何在android项目中获取文件路径,java,android,junit,robotium,Java,Android,Junit,Robotium,我在android eclipse中有一个项目,它将在android emulator上运行。 在我的项目中,我将一些xlf(xml格式)文件放在文件夹translations中。我将阅读并解析它们。但我似乎总是失败。 我的项目结构类似于附件图像 TC01_OSNdemo.java是我的主包。 在其中,我编写了解析“translations”文件夹中xml文件的代码。 但似乎无论在绝对路径、相对路径等方面都失败了 我的方法1:相对路径 String FileName = "./translat

我在android eclipse中有一个项目,它将在android emulator上运行。 在我的项目中,我将一些xlf(xml格式)文件放在文件夹translations中。我将阅读并解析它们。但我似乎总是失败。 我的项目结构类似于附件图像

TC01_OSNdemo.java是我的主包。 在其中,我编写了解析“translations”文件夹中xml文件的代码。 但似乎无论在绝对路径、相对路径等方面都失败了

我的方法1:相对路径

String FileName = "./translations/myosn.mofile.android.zn_CN.xlf"
File tfile = new File(FileName);
                        if (tfile.exists())
                        {
                            System.out.println("zhaotest File exist");
                        }
                        else
                        {
                            System.out.println("zhaotest File Not Exist");
                        }
似乎找不到文件了

我的方法2。我的项目中的绝对路径

String FileName = "C:\\Users\\****\\workspaceforandroid\\OSNdemo\\translations\\myosn.mofile.android.zn_CN.xlf";
似乎找不到文件了

我的方法3

String FileName = Environment.getExternalStorageDirectory()+ File.separator+ "OSNdemo" +File.separator + "translations"+File.separator + "myosn.mofile.android.zn_CN.xlf";
似乎找不到文件(

有人能帮我解决这个问题吗

非常感谢

assets/
You can use it to store raw asset files. Files that you save here are compiled into 
an .apk file as-is, and the original filename is preserved. You can navigate this directory in the 
same way as a typical file system using URIs and read files as a stream of bytes using the 
AssetManager. For example, this is a good location for textures and game data.

使用assest文件夹放置xlsfile@NaveenTamrakar,这是否意味着android无法解析xml格式的文件?正如@Naveentamakar所说,你可以使用资产来放置你的文件,这是一个如何使用它们的示例,没有它可以解析,但你将xml文件放在本地服务器上,比如SD卡上,放在应用内资源上,这意味着你必须放置文件你的应用程序要在资产文件夹中使用。此外,你必须使用资产管理器打开输入流来读取文件。你不能使用文件类或FileInputStream类。文件名应全部为小写。明白了,非常感谢!