Android的MKDIR不做文件夹 [英] Android mkdir not making folder
问题描述
今晚,我现在有做的事情,我认为将是简单的问题......让在到/ mnt / SD卡的文件夹。
Tonight I am currently having issues doing something that I thought would be simple... making a folder in /mnt/sdcard.
我已经设置了如下权限:
I have set the follow permission:
<uses-permission android:name="android.permission.WRITE_EXTERNAL_STORAGE"></uses-permission>
我的 Main.java
具有以下,以使该文件夹:
My Main.java
has the following to make the folder:
public class Main extends TabActivity {
static int index = 1;
private static final String TAG = "Main";
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.main);
File folder = new File(Environment.getExternalStorageDirectory () + "/tallgrass/images");
boolean success = false;
if(!folder.exists()){
success = folder.mkdir();
}
if (!success){
Log.d(TAG,"Folder not created.");
}
else{
Log.d(TAG,"Folder created!");
}
}
我得到的文件夹中创建!在我的日志信息,但是当我同时检查到/ mnt / SD卡
和 / SD卡
没有一个具有文件夹。我已经打过电话:
I get the "Folder created!" message in my log but when I check both /mnt/sdcard
and /sdcard
neither one has the folder. I have tried calling:
Environment.MEDIA_MOUNTED.equals(Environment.getExternalStorageState())
和它返回true。我实在不明白这一个,因为所有迹象都指向它应该工作。我也试图与来自以防SD卡被安装或作为我目前使用模拟器的我的手机,而不是用于开发一些电脑断开手机。说到这,确实可调试
到真
可能作出的文件夹prevent呢?
and it returns true. I just can't figure this one out because all signs are pointing that it should work. I have also tried it with the phone disconnected from the PC in case the SD card was mounting or something as I am currently using my phone instead of the emulator for developing. Speaking of which, does debuggable
to true
maybe prevent it from making the folder?
谢谢!
推荐答案
请问到/ mnt / SD卡/高杆草/
目录是否存在? (我猜没有,但你永远不知道。)
Does the /mnt/sdcard/tallgrass/
directory exist? (I'm guessing not, but you never know.)
的<一个href="http://developer.android.com/reference/java/io/File.html#mkdirs%28%29"><$c$c>File.mkdirs()$c$c>方法将创建所有必需的目录; 的mkdir()
将只创建的最后的路径名目录。
The File.mkdirs()
method will create all needed directories; mkdir()
will only create the last directory in the pathname.
这篇关于Android的MKDIR不做文件夹的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!