在android的sd卡中能创建文件但是不能创建文件夹怎么解决

a465456465 a465456465 墨衍会员 · AI 创作全网分发 墨衍智能分发 通过墨衍一键同步至各平台 可同步平台 CSDN微信公众号微博知乎掘金百家号博客园抖音小红书 你的文章也可以这样分发 墨衍会员 ¥399起/年,写一次发全网 我也要 + 加入社区
各位高烧怎么在sd卡中能创建文件就是不能创建文件夹呢?权限我全加上了
<uses-permission android:name="android.permission.MOUNT_UNMOUNT_FILESYSTEMS"/>
<uses-permission android:name="android.permission.WRITE_EXTERNAL_STORAGE" />

public static void checkedAndSaveFile(String fileName,String data,String path){
InputStream inputStream = new java.io.ByteArrayInputStream(StringUtil.fromBase64(data));
String savePath = path.trim();
savePath = savePath.replace("\\", "/");
String saveFileName = fileName.trim();
String saveFilePathAndName = savePath+File.separator+saveFileName;
Log.i("dir======================>", saveFilePathAndName);
saveFilePathAndName=saveFilePathAndName.trim();
File newFile = new File(saveFilePathAndName);
File fileDir = new File(savePath);
if(!fileDir.exists()){
fileDir.mkdir();
}
//
File file = new File(Environment.getExternalStorageDirectory().getAbsolutePath() + File.separator + "test.txt");
try {
file.createNewFile();
} catch (IOException e1) {
e1.printStackTrace();
}
//
if(!newFile.exists())
try {
newFile.createNewFile();
} catch (IOException e) {
e.printStackTrace();
}
if(checkSDCard()){
save(saveFilePathAndName, inputStream, newFile);
}
}

public static void save(String fileName,InputStream inputStream,File file){

FileOutputStream fos = null;
try {
fos = new FileOutputStream(file);
byte[] buffer = new byte[512];
int len;
int downloader = 0;
while ((len = inputStream.read(buffer)) != -1) {
fos.write(buffer, 0, len);
downloader += len;
}
} catch (FileNotFoundException e) {
e.printStackTrace();
} catch (IOException e) {
e.printStackTrace();
}finally{
try {
fos.flush();
fos.close();
inputStream.close();
} catch (IOException e) {
e.printStackTrace();
}
}
}
...全文
评论 5
收藏 已收藏
分享
返回顶部
a465456465
Android 80,490 成员 91,371 内容