如何写在Android的外部文本文件?写在、文本文件、Android

2023-09-04 06:11:06 作者:Rogue(流氓)

我想写在Android项目(使用Eclipse)一个文本文件中的串线。这是code,而我试图,但其不工作...

I want to write a string line in a text file in android project (using Eclipse). This is the code which i am trying but its not working...

    String s="hello azeem\n";
    try{
    FileOutputStream fos = openFileOutput("C:\\eventslog.txt", Context.MODE_PRIVATE);
    fos.write(s.getBytes());
    fos.close();
    }
    catch (Exception e){

    }

任何想法??

Any ideas??

推荐答案

有两种方式来理解你的问题:

There are two ways to understand your question:

您想要写入文件到c:在您的计算机驱动器 - 以及您不能。如果你想从Android的某些文件保存到计算机编程,你就必须将它通过网络,发送 您想写一些地方在android FS - c在这种情况下:\ 是irreleveant,因为这是一个窗口的路径,并基于Android的UNIX,这意味着所有路径从根开始( / )也,Android的SDK提供了几个方法来访问相关的目录中的文件,而无需使用一个固定的路径。在这里看到: http://developer.android.com/guide/topics/数据/数据​​storage.html You want to write the file to c: drive in your computer - well you can't. If you want to save some file from android to your computer programmatic, you'll have to send it via network. You want to write to some place in the android FS - in this case c:\ is irreleveant, since this is a windows path, and android is unix based, meaning all paths start from root (/) also, android SDK provides you a few methods to access relevant directories files without using a fixed path. see here: http://developer.android.com/guide/topics/data/data-storage.html