如何建立在Android设备的根目录/写文件? [英] How to create/write file in the root of the android device?

查看:1162
本文介绍了如何建立在Android设备的根目录/写文件?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我发现,您可以使用像这样创建一个文件:

I found out that you can use something like this to create a file:

FileOutputStream  fs = openFileOutput("/test.in", MODE_WORLD_WRITEABLE);
String s = "[Head]\r\n";
s += "Type=2";
byte[] buffer = s.getBytes();
fs.write(buffer);
fs.close();

在运行上面的code,我得到一个IllegalArgumentException说明:

When running the above code I get an IllegalArgumentException stating:

java.lang.IllegalArgumentException异常:   文件/test.in包含一个路径   分离

java.lang.IllegalArgumentException: File /test.in contains a path separator

和即时猜测的/是不是AP preciated。我想要的/,因为我需要写文件到设备的根目录下,如在API中规定在努力遵循:

and Im guessing the "/" is not appreciated. I wanted the "/" since I need to write the file to the root directory of the device, as stated in the API in trying to follow:

一个请求是一个文本文件(UNI code)与   文件扩展名。在。该   应用程序读取并分析。在   当它放置在根文件   在移动设备上的目录。

A request is a textfile (UNICODE) with the file extension ".in". The application reads and parses the .in file when it's placed in root directory on the mobile device.

问题是:我如何在根目录中的文件?我一直在四处寻找一个答案,但还没有找到过。

Question is: how do I place a file in the root-directory? I have been looking around for an answer, but havent found one yet.

关于

推荐答案

Context.openFileOutput是指用于创建文件专用于您的应用程序。他们走在你的应用程序的私有数据目录。你提供一个的名称的,而不是一个路径:命名文件的打开的名称;不能包含路径分隔符

Context.openFileOutput is meant to be used for creating files private to your application. they go in your app's private data directory. you supply a name, not a path: "name The name of the file to open; can not contain path separators".

<一个href="http://developer.android.com/reference/android/content/Context.html#openFileOutput(java.lang.String">http://developer.android.com/reference/android/content/Context.html#openFileOutput(java.lang.String, INT)

对于你的问题,你不能写入/除非你是根:

as for your question, you can't write to / unless you're root:

我的Linux的盒子$亚行外壳的ls -l -d / drwxr-XR-X根根2010-01-16 07:42 $

my-linux-box$ adb shell ls -l -d / drwxr-xr-x root root 2010-01-16 07:42 $

我不知道你的API是什么期待你写的根目录下,但我猜这不是一个Android API和你读错的文件; - )

i don't know what your API is that expects you to write to the root directory, but i'm guessing it's not an Android API and you're reading the wrong documentation ;-)

这篇关于如何建立在Android设备的根目录/写文件?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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