在android的sd卡中能创建文件但是不能创建文件夹怎么解决
各位高烧怎么在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();
}
}
}
<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();
}
}
}
...全文
相关推荐
Android 创建txt文件存到SD卡,向txt文件写入内容,读出txt文件内容
Android 创建txt文件存到SD卡,向txt文件写入内容,读出txt文件内容 https://blog.csdn.net/qq_31939617/article/details/80911397
Android SD卡文件夹操作实践:创建与删除
在Android中,File类是一个非常重要的类,它可以用来操作文件系统。无论是文件还是目录,都可以使用File类来表示它们。File类提供了一系列的方法来创建、删除、重命名文件和目录,以及获取文件的状态信息等。以下是File类常用的一些方法:mkdir(): 创建一个目录,如果创建成功返回true,否则返回false。mkdirs(): 创建一个目录,包括创建不存在的父目录,如果创建成功返回true,否则返回false。
Android-SD卡文件夹创建和删除实现
Android-SD卡文件夹创建和删除实现 * 获取SD卡中的目录 * 功能: * 创建文件夹,删除文件夹,返回键退出程序 * ListView 使用BaseAdapter
android读取sd卡中音乐文件列表
android通过代码读取手机sd卡中的音乐文件,放在adapter中,然后放到一个ListView中,做音乐列表
android读取sd卡中MP3文件
android读取sd卡中MP3文件


