public void onPictureTaken(byte[] data, Camera camera)
{
Intent imageIntent = new Intent(android.provider.MediaStore.ACTION_IMAGE_CAPTURE);
File imagesFolder = new File(Environment.getExternalStorageDirectory(), "Raw Image");
imagesFolder.mkdirs();
Date d = new Date();
CharSequence s = DateFormat.format("MM-dd-yy hh-mm-ss", d.getTime());
File output = new File(imagesFolder, s.toString() + ".jpg");
Uri uriSavedImage = Uri.fromFile(output);
imageIntent.putExtra(MediaStore.EXTRA_OUTPUT, uriSavedImage);
OutputStream imageFileOS;
try {
imageFileOS = getContentResolver().openOutputStream(uriSavedImage);
imageFileOS.write(data);
imageFileOS.flush();
imageFileOS.close();
};
目前我正在创建一个文件夹名称“Raw Image”来保存图像。如果我想在“Raw Image文件夹”中创建更多文件夹,该怎么办?请提出任何建议。
答案 0 :(得分:1)
通过这种方式,您将在“Raw Image”文件夹中创建一个名为“another_folder”的文件夹:
File imagesFolder = new File(Environment.getExternalStorageDirectory(), "Raw Image/another_folder");
此外,您应该避免在名称中创建带空格的文件夹/文件
答案 1 :(得分:1)
您必须检查文件夹是否已存在。你只需要添加一行代码
File imagesFolder = new File(Environment.getExternalStorageDirectory(), "Punch");
if (!imagesFolder.exists()) {
imagesFolder.mkdirs();
}
else { //do nothing
}
答案 2 :(得分:1)
尝试以下代码
File imagesFolder = new File(Environment.getExternalStorageDirectory(), "Raw Image");
File folder= new File(imagesFolder , "yourfolder name");
folder.mkdirs();