保存BitMap到本地

/** * *  * @param context * @param mBitmap * @return */public static String saveBitmap(Context context, Bitmap mBitmap) {String savePath = null;File filePic;if (Environment.getExternalStorageState().equals(Environment.MEDIA_MOUNTED)) {savePath = Environment.getExternalStorageDirectory().getAbsolutePath() + "/zplay";} else {savePath = Environment.getDataDirectory().getAbsolutePath()+ "/zplay";}try {filePic = new File(savePath + "/"+ (System.currentTimeMillis() / 1000) + ".jpg");if (!filePic.exists()) {filePic.getParentFile().mkdirs();}FileOutputStream fos = new FileOutputStream(filePic);mBitmap.compress(Bitmap.CompressFormat.JPEG, 90, fos);fos.flush();fos.close();return filePic.getAbsolutePath();} catch (IOException e) {e.printStackTrace();}return "";}

保存File到本地

 File file = getFile("/zplay/1.mp4");        try {            InputStream inputStream = getAssets().open("1.mp4");            Log.i(TAG, "--file " + file.getAbsolutePath());            if (!file.exists()) {                //创建文件夹                //file.mkdirs();                //创建文件                file.createNewFile();                FileOutputStream fileOutputStream = new FileOutputStream(file);                byte[] arr = new byte[1024 * 1024];                int temp = -1;                while ((temp = inputStream.read(arr)) != -1) {                    fileOutputStream.write(arr);                    fileOutputStream.flush();                    Log.i(TAG, "--temp=" + temp);                }                inputStream.close();                fileOutputStream.close();            }        } catch (IOException e) {            e.printStackTrace();        }

private File getFile(String path) {        File file = null;        String state = Environment.getExternalStorageState();        if (state.equals(Environment.MEDIA_MOUNTED)) {            //存在sd卡            file = new File(Environment.getExternalStorageDirectory().getAbsolutePath() + path);        } else {            file = new File(Environment.getDownloadCacheDirectory().getAbsolutePath() + path);        }        return file;    }


更多相关文章

  1. Android:创建快捷方式
  2. android 创建快捷方式图标
  3. android文件操作的实例
  4. android屏幕截图
  5. Android文件保存和读取
  6. Android(安卓)Shareperferences使用
  7. Android(安卓)Activity从创建到显示流程
  8. Android应用程序窗口(Activity)的运行上下文环境(Context)的创建过程
  9. Android流媒体播放器

随机推荐

  1. android最全总结
  2. Error pulling origin: error: Your loca
  3. Android(安卓)中级教程之------Android(
  4. Android实现图片毛玻璃背景效果
  5. Android(安卓)网络开发
  6. Android(安卓)BroadCast类讲解
  7. Android(安卓)8.0 悬浮窗变动与用法
  8. Android(安卓)setTextColor 不生效
  9. 【Appium + Python3】之安卓8.1,使用xpath
  10. 【Animation】 使用handler和Runnable实