File dir = Environment.getExternalStorageDirectory();
if (dir.exists() && dir.isDirectory()) {
String exStoragePath = Environment.getExternalStorageDirectory().getAbsolutePath();
File appPath = new File(exStoragePath + "/mbrc/");
appPath.mkdirs();
String tempFilename = "tmp.wav";
String tempDestFile = appPath.getAbsolutePath() + "/" + tempFilename;
return tempDestFile;
}
我在使用Android 2.2的HTC上尝试此操作,但目录未创建,文件也没有。如果我在SAMSUNG S2 wuth android 4上尝试这个就可以了。
为什么这不适用于HTC和Android 2.2?
答案 0 :(得分:1)
您需要创建文件。
http://docs.oracle.com/javase/7/docs/api/java/io/File.html#createNewFile()
File dir = Environment.getExternalStorageDirectory();
if (dir.exists() && dir.isDirectory()) {
String exStoragePath = Environment.getExternalStorageDirectory().getAbsolutePath();
File appPath = new File(exStoragePath + "/mbrc/");
appPath.mkdirs();
String tempFilename = "tmp.wav";
String tempDestFile = appPath.getAbsolutePath() + "/" + tempFilename;
File newFile = new File(tempDestFile);
newFile.createNewFile();
return tempDestFile;
}