如何写在Android的外部文本文件? [英] How to write to an external text file in Android?

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

问题描述

我想写在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:

  1. 您想要写入文件到c:在您的计算机驱动器 - 以及您不能。如果你想从Android的某些文件保存到计算机编程,你就必须将它通过网络,发送
  2. 您想写一些地方在android FS - c在这种情况下:\ 是irreleveant,因为这是一个窗口的路径,并基于Android的UNIX,这意味着所有路径从根开始( / )也,Android的SDK提供了几个方法来访问相关的目录中的文件,而无需使用一个固定的路径。在这里看到: http://developer.android.com/guide/topics/数据/数据​​storage.html
  1. 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.
  2. 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

这篇关于如何写在Android的外部文本文件?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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