代码如下:
String folderPath = Environment.getExternalStorageDirectory() + "/AllAroundMe/Images";
File file = new File(folderPath);
if(!file.exists())
{
if(file.mkdirs());
Log.d("MyTag","Created folders succefully");
}
if(file.exists())
{
Log.d("MyTag", "folders exists: " + file.getAbsolutePath());
}第二个if从来没有发生过,它应该发生,因为我制作了这些dirs。我的代码出了什么问题?顺便说一句,每次我运行这个程序时,它总是处于第一个状态。
发布于 2012-10-23 02:24:33
确保你有
<uses-permission android:name="android.permission.WRITE_EXTERNAL_STORAGE" />在您的android.manifest文件中。
另外,像这样构造file对象会更好:
String folderPath = "AllAroundMe/Images";
File file = new File(Environment.getExternalStorageDirectory(), folderPath);发布于 2012-10-23 02:13:44
我认为你应该删除semi-colon后面的那个内部,如果:-
if(file.mkdirs()) {
Log.d("MyTag","Created folders succefully");
}P.S:-这就是为什么你应该总是使用大括号,即使你只有一个if语句,这样你就不会犯这样的错误。
https://stackoverflow.com/questions/13017158
复制相似问题