宝塔服务器面板,一键全能部署及管理,送你10850元礼包,点我领取

//android 内部存储自定义目录写入文件

try{
File testDir = new Filethis.getFilesDir).getAbsolutePath) + File.separator + "myFolder");
if!testDir.exists)){
  testDir.mkdir);
}

f = new FiletestDir, "test.txt");
FileOutPutStream fos = new FileOutPutStreamf); 
...
}
catchIOException e) { e.printStackTrace); }
//android 外部存储自定义目录(手机自带存储也属于外部存储)

/*Environment.getExternalStorageDirectory)取得机器的SD卡位置,File.separator为分隔符“/”*/

private final static String myPath=Environment.getExternalStorageDirectory)+File.separator+"myFolder";

boolean sdCardExist = Environment.getExternalStorageState).equalsandroid.os.Environment.MEDIA_MOUNTED);
        if!sdCardExist){

            Toast.makeTextMainActivity.this, "请插入外部SD存储卡",Toast.LENGTH_SHORT).show);

        }else {
            //如果存在SD卡,判断文件夹目录是否存在
            File dirFile = new FilemyPath);
            //判断文件夹目录是否存在
            if !dirFile.exists)) {
                dirFile.mkdir);//如果不存在则创建
            }
        }     

注意:多级目录必须逐一创建