Android设备上保存XML文件,阅读 [英] Save XML file on Android device and read it

查看:142
本文介绍了Android设备上保存XML文件,阅读的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有存储和读取我的宏碁ICONIA TAB A 100的XML文件的问题。

I have issues with storing and reading an XML file on my Acer Iconia Tab A 100.

我遵循的步骤是:

1)插入到我的系统。

1) Plug in the tab to my system.

这是我的笔记本电脑宏碁ICONIA TAB / SD卡/ MYDIR /的test.xml

2) Copy test.xml file from my laptop to Acer Iconia Tab/ SDCard/ mydir/test.xml

3)尝试打开的Andr​​oid code这个文件,内容如下:

3) Try to open this file in Android code, as follows:

   File testFile = null;
   File dir = new File(android.os.Environment.getExternalStorageDirectory(),"mydir");
   if(dir.exists())
   testFile = new File(dir, "test.xml");

   if (testFile != null) 
        Log.d ("File length="+testFile.length());       // returns 0

当我执行上述code,它打印出的长度为0。我已经尝试过其他组合如下,却徒劳无功:

When I execute the above code, it prints out the length as 0. I have tried other combination as follows, but in vain:

   File dir = new File("/data","mydir");

   File dir = new File("/mnt/sdcard","mydir");

有人可以帮助?

感谢。
阿尼

推荐答案

文件长度

public long length()

返回由此抽象路径名表示的文件的长度。返回值是不确定的,如果此路径名表示一个目录。

Returns the length of the file denoted by this abstract pathname. The return value is unspecified if this pathname denotes a directory.

返回:
        长度,以字节为单位,此抽象路径名表示的文件,或者0L如果文件不存在

所以只是检查,文件是否存在与否,

So just check it, whether file exist or not,

通过使用 File.exist();

此外,通过查看文件管理器 - > DDMS通过Eclipse找到该文件的具体路径。它还显示文件大小。

Also, By looking in File Explorer -> DDMS via eclipse find the exact path of the file. It also show size of the file.

这篇关于Android设备上保存XML文件,阅读的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆