【发布时间】:2016-01-05 02:38:55
【问题描述】:
这是我保存图像的代码。我还提到了我要保存图像的文件夹名称,因此它将在画廊中,但它不起作用我的图像被保存在默认的“图片”文件夹中。当我调试时,它显示
java.io.FileNotFoundException:/storage/emulated/0/MyFolderName/aaa-13:15:44/1-4-2016.jpg:打开失败:ENOENT(没有这样的文件或目录) em>
异常。在执行第一行 try 块后,它会去 catch 文件夹。
请帮忙,我错过了什么????
提前谢谢你...
public void saveImage(Bitmap bitmap){
String root = Environment.getExternalStorageDirectory().toString();
File myDir = new File(root + "/MyFolderName"); //my folder name where I want to save.
String receiverN = receiverName.getText().toString();
myDir.mkdirs();
Calendar c = Calendar.getInstance();
String month, day, year, hour, minute, second;
month = ""+ (c.get(Calendar.MONTH)+1);
day = "" + c.get(Calendar.DAY_OF_MONTH);
year = "" + c.get(Calendar.YEAR);
hour = ""+c.get(Calendar.HOUR_OF_DAY);
minute = "" + c.get(Calendar.MINUTE);
int seconds = c.get(Calendar.SECOND);
if (seconds<10) second = "0"+ seconds;
else second = ""+seconds;
String fname = receiverN + "-" + hour + ":" + minute + ":" + second + "/" + month + "-" + day + "-" + year +".jpg";
File file = new File (myDir, fname);
if (file.exists ()) file.delete ();
try {
FileOutputStream out = new FileOutputStream(file); //from here it goes to catch block
bitmap.compress(Bitmap.CompressFormat.JPEG, 90, out);
out.flush();
out.close();
String[] paths = {file.toString()};
String[] mimeTypes = {"/image/jpeg"};
MediaScannerConnection.scanFile(this, paths, mimeTypes, null);
} catch (Exception e) {
e.printStackTrace();
}
}
【问题讨论】:
标签: android android-intent android-activity bitmapimage android-bitmap