我是Android编程新手。我已经搜索了很多并尝试了我能得到的所有代码,但似乎无法在我的NEXUS 4设备上创建目录。可以请有人帮助我。感谢
这是我已经做过的工作:
public class MainActivity extends Activity {
public static String TAG="YOUR_ACTIVITY_NAME";
private String filename = "MySampleFile.txt";
private String filepath = "MyFileStorage";
File myInternalFile;
@Override
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
String FILE_NAME = "MyMusic.mp3";
File path = Environment.getExternalStoragePublicDirectory(
Environment.DIRECTORY_PICTURES);
File file = new File(path, FILE_NAME);
path.mkdirs();
}
答案 0 :(得分:1)
您需要使用File.mkDirs()
方法。例如:
File sub = new File(context.getFilesDir(), "subdirectory");
if (!sub.exists())
sub.mkdirs();