Android文件操作

来源:互联网 发布:网络视频会议设备 编辑:程序博客网 时间:2024/06/06 09:20

查看文件夹是否存在,存在保存文件,不存在创建文件夹并保存。

public static void savePic(Bitmap bitmap, String name) {

if (Environment.MEDIA_MOUNTED.equals(Environment
.getExternalStorageState())) {

File path1 = new File(.picAddress);

if (!path1.exists()) {             //判断文件夹是否存在
path1.mkdirs();
}
String str =picAddress + name +".png";   //文件名


Log.d("savePic", str);
File file = new File(str.toString().trim());
try {
FileOutputStream outPut = new FileOutputStream(file);

bitmap.compress(Bitmap.CompressFormat.JPEG, 100, outPut);  //将数据放到文件中

try {
outPut.flush();
outPut.close();
} catch (IOException e) {
e.printStackTrace();
}
} catch (FileNotFoundException e) {
e.printStackTrace();
}
} else {

return;
}
}
0 0