如何建立在Android中的目录? [英] How to create a directory in Android?

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

问题描述

一切都在的问题。这是我的code:

Everything is in the question. Here is my code :

    private void createDirectory(File currentDirectory) {
  File f = null;
  try {

   f = new File(currentDirectory.getCanonicalPath() + "/directory"
     + count);

   boolean success = f.mkdir();
   if (!success) {
    Toast.makeText(currentContext,
      f.getName() + " could not be created", 15).show();

   }
  } catch (IOException ioe) {
   Toast.makeText(currentContext,
     f.getName() + " could not be created", 15).show();
  }

  count++;
 }

我写在Android中一个小的文件管理器,我想补充,以创建一个目录的可能性。有没有例外和可变成功总是返回false。 谁能告诉我什么是错我的code ??

I am writing a small file manager in Android and I would like to add the possibility to create a directory. There is no exception and the variable success always return false. Can someone tell me what is wrong my code??

THX您的意见!

顺便说一句,当手机处于发展署模式,并应用对SD卡的写访问?我编程我的手机上(宏碁Liquid)

BTW, When the phone is in Developpement mode, does an application has a write access on the sdcard? I am programming on my phone (Acer liquid)

推荐答案

您需要添加此权限:

<uses-permission android:name="android.permission.WRITE_EXTERNAL_STORAGE" />

顺便说一句,不知道你是如何得到的SD卡目录...但它必须是这样的:

By the way, not sure how you are getting the SDcard directory... but it must be this way:

File sdDir = Environment.getExternalStorageDirectory();

这一点很重要,因为有些程序员使用来认为SD卡始终/ SD卡,但它可能会改变。

It's important, because some programmers use to think that the SDCard is always /sdcard, but it could change.

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

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