【问题标题】:how to read file from the phone memory in android?如何从android中的手机内存中读取文件?
【发布时间】:2010-07-23 08:45:04
【问题描述】:

我需要从手机内存中读取文件。如何读取文件?谁能帮助我?

【问题讨论】:

    标签: android


    【解决方案1】:

    以下是如何写入文件..

    FileOutputStream fos = openFileOutput("urls.txt", Context.MODE_PRIVATE);
    fos.write("Alex".getBytes());
    fos.close();
    

    读取该文件的方法如下:

    FileInputStream fis = openFileInput("urls.txt");
    int c;
    while((c=fis.read())!=-1)
            {
    
                k += (char)c;
            }
    fis.close();
    

    字符串 k 将包含“Ankit”作为字符串。

    请注意..文件“urls.txt”在手机内存中形成,您无法在项目中将该文件作为资源访问。

    欲了解更多信息,请参阅:http://developer.android.com/guide/topics/data/data-storage.html#filesInternal

    【讨论】:

    • 我的文件在以下路径 content://com.android.email.attachmentprovider/1/1/RAW 这个怎么读?
    【解决方案2】:

    (通过谷歌搜索)

    从内部存储读取文件:

    1. 调用openFileInput() 并将要读取的文件的名称传递给它。这将返回一个 FileInputStream。
    2. 使用read() 从文件中读取字节。
    3. 然后使用 close() 关闭流。

    参考:http://developer.android.com/guide/topics/data/data-storage.html#filesInternal

    【讨论】:

    • 我的文件在以下路径 content://com.android.email.attachmentprovider/1/1/RAW 这个怎么读?
    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 2021-12-30
    • 1970-01-01
    • 2016-08-29
    • 2012-05-07
    • 2015-04-08
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多