需要写一个方法
public void saveFile(Bitmap bm, String fileName)
throws IOException { File dirFile =
new File(Environment.
getExternalStorageDirectory().getPath());
if (!dirFile.exists()) { dirFile.mkdir(); } fileName = UUID.
randomUUID().toString() +
".jpg"; File jia =
new File(Environment.
getExternalStorageDirectory().getPath() +
"/imgpic/");
if (!jia.exists()) {
//判断文件夹是否存在,不存在则创建 jia.mkdirs(); } File myCaptureFile =
new File(jia +
"/" + fileName); BufferedOutputStream bos =
new BufferedOutputStream(
new FileOutputStream(myCaptureFile)); bm.compress(Bitmap.CompressFormat.
JPEG,
80, bos); bos.flush(); bos.close(); }
然后再需要放的资源里面放、
saveFile(
bitmap, Environment.
getExternalStorageDirectory() +
"/imgpic/");
这个bitmap可以是一个图片 可以是一个文件