Android 文件处理
2016-12-05 00:00
281 查看
public static void copy(InputStream fis, OutputStream fos) throws IOException{ try{ byte[] buf = new byte[1024]; int len = 0; while((len = fis.read(buf))>0){ fos.write(buf, 0, len); } }finally{ if(fis!=null){ try { fis.close(); } catch (IOException e) { e.printStackTrace(); } } if(fos !=null){ try { fos.close(); } catch (IOException e) { e.printStackTrace(); } } } } public static byte[] getBytes(InputStream fis) throws IOException{ ByteArrayOutputStream fos = null; byte[] data = null; try{ fos = new ByteArrayOutputStream(); byte[] buf = new byte[1024]; int len = 0; while((len = fis.read(buf))>0){ fos.write(buf, 0, len); } return fos.toByteArray(); }finally{ if(fos !=null){ try { fos.close(); } catch (IOException e) { e.printStackTrace(); } } } }
public static boolean saveBitmap(Bitmap bmp, String filePath){ if(bmp == null){ return false; } File f = new File(filePath); FileOutputStream fos = null; try{ f.delete(); f.createNewFile(); fos = new FileOutputStream(f); bmp.compress(CompressFormat.PNG, 100, fos); fos.close(); return true; }catch(Exception e){ e.printStackTrace(); return false; }finally{ if(fos!=null){ try { fos.close(); } catch (IOException e) { e.printStackTrace(); } } } }
相关文章推荐
- Android系统的超级终端命令大全(三)--文件处理命令
- Android开源项目发现--- 工具类文件处理篇(持续更新)
- Android开源项目发现--- 工具类文件处理篇(持续更新)
- 谷歌重奖1000万美元推动手机系统Android普及
- Android 原代码下载路径
- 体验Android:个人所得税计算器 含源码
- 体验Android
- 体验Android
- Google 1000万美元重奖Android开发者
- Android安装以及Eclipse插件(Google Android) ,在Android 中google搜索 博客园界面
- Android,来自google的手机平台
- Google Android SDK和Eclipse插件的安装
- Android 采用了Apache Harmony的代码
- Google开发人员访谈 Android平台探秘
- Android 不得不写一下了
- Android 架构
- Linux必须学会的60个命令---文件处理一(转载)
- Google Buys Android for Its Mobile Arsenal
- Android仿新浪微博、QQ空间等帖子显示(2)
- Linux必学的60个命令(2)-文件处理