package com.img.util; import java.io.File; import java.io.FileNotFoundException; import java.io.FileOutputStream; import java.io.IOException; import java.util.Calendar; import android.graphics.Bitmap; import android.os.Environment; public class FileUtils { private static String getRootFilePath() { StringBuffer stbPath = new StringBuffer(); stbPath.append(Environment.getExternalStorageDirectory().getPath()); stbPath.append(File.separator); stbPath.append("example"); stbPath.append(File.separator); return stbPath.toString(); } public static void saveImage(final Bitmap bitmap) throws IOException, FileNotFoundException { // SD������ if (Environment.getExternalStorageState().equals( Environment.MEDIA_MOUNTED)) { // �����ļ�Ŀ¼ File f = new File(getRootFilePath()); f.mkdirs(); // ��ȡ�ɹ� if (bitmap != null) { // ��ȡ��ǰϵͳʱ�� Calendar cl = Calendar.getInstance(); cl.setTime(Calendar.getInstance().getTime()); long milliseconds = cl.getTimeInMillis(); // ��ǰϵͳʱ����Ϊ�ļ��� String fileName = String.valueOf(milliseconds) + ".jpg"; // ����ͼƬ // �����ļ� File file = new File(getRootFilePath(), fileName); file.createNewFile(); if (!file.isFile()) { throw new FileNotFoundException(); } FileOutputStream fOut = null; fOut = new FileOutputStream(file); // ��ͼƬתΪ����� bitmap.compress(Bitmap.CompressFormat.JPEG, 100, fOut); // �ر������ fOut.flush(); fOut.close(); } } } public static String getTakePhotoPath() { return getCacheFile().getPath() + File.separator + "takephoto.jpg"; } /** * �õ������ļ��� */ public static File getCacheFile() { StringBuffer sb = new StringBuffer(); sb.append(Environment.getExternalStorageDirectory().getPath()); sb.append(File.separator); sb.append("Android"); sb.append(File.separator); sb.append("data"); sb.append(File.separator); sb.append("cache"); sb.append(File.separator); File file = new File(sb.toString()); return file; } }