0

I have a project in android eclipse, and it will be run on android emulator. In my project, I put some xlf (xml format) files in the folder translations. And I will read them and parse. But it seems I always fail. The structure of my project is like attachment image enter image description here

And TC01_OSNdemo.java is my main package. In it, I wrote the codes to parse xml files from "translations" folder. But it seems it fail no matter in absolute path, relative path, etc...

My method1: relative path

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");
                        }

It seems it can't find the file

My method 2. absolute path in my project.

String FileName = "C:\\Users\\****\\workspaceforandroid\\OSNdemo\\translations\\myosn.mofile.android.zn_CN.xlf";

It seems it can't find the file.

My method 3.

String FileName = Environment.getExternalStorageDirectory()+ File.separator+ "OSNdemo" +File.separator + "translations"+File.separator + "myosn.mofile.android.zn_CN.xlf";

It seems it can't find the file. :(

Could anyone help me about this issue?

Thanks a lot!

zhaojing
  • 585
  • 3
  • 11
  • 33
  • use assest folder to put xls file – Naveen Tamrakar Nov 12 '14 at 09:34
  • @NaveenTamrakar, Does it means android can't parse xml format files? – zhaojing Nov 12 '14 at 09:39
  • as @NaveenTamrakar says, you can use assets to put your files, this is an example how to use them http://stackoverflow.com/a/8475135/4224337 – Rami Nov 12 '14 at 09:40
  • no its can parse but where u put xml file like on server on local Like Sdcard on in App Resource – Naveen Tamrakar Nov 12 '14 at 09:40
  • No it means that you have to put files which your app wants to use in the assets folder. Moreover you have to use assets manager to open an input stream to read the file. You can not use the File class or FileInputStream class. The filename should be all lowercase. – greenapps Nov 12 '14 at 09:40

1 Answers1

1
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.

Android Projects structure

SMMH
  • 310
  • 1
  • 13
Naveen Tamrakar
  • 3,349
  • 1
  • 19
  • 28