java将所选文件保存在安卓 SD卡中
如何将用户选择的文件保存到安卓 SD卡的特定文件夹中
我跟踪了this article here that helped me a lot,但我不知道在那之后如何保存它
我能够保存选定的图像和拍摄的图片。这是我使用的代码
private String saveBitmapToInternalSorage(Bitmap bitmapImage){
// get dir
File dir = new File(Environment.getExternalStorageDirectory(), "myApp/app-files");
if (!dir.mkdirs()){
Log.w("Could not create log directory: " + dir.getAbsolutePath(), "");
}
String fileName = "";
if (ChecklistHandler.getWorkingItem().getChildren() == null ||
ChecklistHandler.getWorkingItem().getChildren().isEmpty()){
fileName = ChecklistHandler.getWorkingItem().getId()
+ "_" + ChecklistHandler.getActivation() + ".jpg";
} else {
fileName = ChecklistHandler.getWorkingItem().getChildren().get(0).
getId() + "_" + ChecklistHandler.getActivation() + ".jpg";
}
File mypath=new File(dir, fileName);
FileOutputStream fos = null;
try {
fos = new FileOutputStream(mypath);
bitmapImage.compress(Bitmap.CompressFormat.PNG, 100, fos);
fos.close();
} catch (Exception e) {
e.printStackTrace();
}
return dir.getAbsolutePath();
}
然后我将引用保存在数据库中给定的文件夹中。 我想对文件做同样的处理。将其保存在同一文件夹中,然后获取引用并保存
共 (0) 个答案