写入到SD卡 [英] writing to sdcard

查看:166
本文介绍了写入到SD卡的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有一个非常小的问题。我写一个文件到SD卡。 I'l显示两个code,一是code的作品和其他没有。它看起来像这样:
第一个,

i have a very small problem. I am writing a file to sdcard. I'l show you two code, one code works and other doesn't. It looks like this: First one,

new FileOutputStream("/sdcard/HelloWorld.txt")

这工作正常,并在SD卡创建HelloWorld.txt文件。

This works fine and creates a HelloWorld.txt file in sdcard.

现在第二个,

  new FileOutputStream(android.os.Environment.getExternalStorageDirectory()+java.io.File.separator + "filetest" + java.io.File.separator + "HelloWorld.txt")

这会引发错误 /mnt/sdcard/filetest/HelloWorld.txt(没有这样的文件或目录)
我想知道为什么,因为我在我的设备上有MNT / SD卡路径,难道是它找不到filetest文件夹,如果是的话那么是不是应该创建filetest文件夹,如果它不是之前创建的。

This throws error "/mnt/sdcard/filetest/HelloWorld.txt (No such file or directory)". I want to know why because i have mnt/sdcard path on my device, is it that it cannot find filetest folder if yes then isn't it supposed to create filetest folder if its not created before.

感谢。

推荐答案

filetest 如果某个目录及其不可用,

First Make a directory of filetest if its not available,

File file = new File(android.os.Environment.getExternalStorageDirectory()+java.io.File.separator + "filetest");

file.mkdir();

然后执行您的code ...

Then execute your code...

File f =    new File(android.os.Environment.getExternalStorageDirectory()+java.io.File.separator + "filetest" + java.io.File.separator + "HelloWorld.txt");

    if (!f.getParentFile().exists());
    {
        f.getParentFile().mkdir();
    }

这篇关于写入到SD卡的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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