IO流拷贝图片的四种方式
来源:互联网 发布:双程网络剧微博 编辑:程序博客网 时间:2024/04/28 09:16
package IO;import java.io.BufferedInputStream;import java.io.BufferedOutputStream;import java.io.File;import java.io.FileInputStream;import java.io.FileOutputStream;import java.io.IOException;public class CopyImg {/** * * IO流复制图片(记事本打开不能读懂),使用字节流 * 4种方式,推荐使用第四种 * */public static void main(String[] args) throws IOException {//数据源File srcfile=new File("数据源");//目的地File destfile=new File("目的地");//methd1(srcfile,destfile);//methd2(srcfile,destfile);//methd3(srcfile,destfile);methd4(srcfile,destfile);}//方式四:缓冲字节流一次读写一个字节数组private static void methd4(File srcfile, File destfile) throws IOException {BufferedInputStream bis=new BufferedInputStream(new FileInputStream(srcfile));BufferedOutputStream bos=new BufferedOutputStream(new FileOutputStream(destfile));byte[] by=new byte[1024];int length=0;while((length=bis.read(by))!=-1){bos.write(by,0,length);}//关闭资源bos.close();bis.close();}/*//方式三:缓冲字节流一次读写一个字节private static void methd3(File srcfile, File destfile) throws IOException {BufferedInputStream bis=new BufferedInputStream(new FileInputStream(srcfile));BufferedOutputStream bos=new BufferedOutputStream(new FileOutputStream(destfile));int by=0;while((by=bis.read())!=-1){bos.write(by);}bos.close();bis.close();}*//*//方式二:基本字节流一次读写一个字节数组private static void methd2(File srcfile, File destfile) throws IOException {FileInputStream fis=new FileInputStream(srcfile);FileOutputStream fos=new FileOutputStream(destfile);byte[] by=new byte[1024];int length=0;while((length=fis.read(by))!=-1){fos.write(by,0,length);}fos.close();fis.close();}*//*//方式一:基本字节流一次读写一个字节private static void methd1(File srcfile, File destfile) throws IOException {FileInputStream fis=new FileInputStream(srcfile);FileOutputStream fos=new FileOutputStream(destfile);int by=0;while((by=fis.read())!=-1){fos.write(by);}fos.close();fis.close();}*/}
0 0
- IO流拷贝图片的四种方式
- IO流:复制图片的四种方式实现
- IO流(拷贝图片)
- IO流--拷贝图片
- IO流拷贝图片
- 使用java的IO字节流拷贝图片
- IO流_复制图片的4种方式案例
- 异步Io的 四种提醒方式方式
- 四种文件(图片)拷贝的方法
- IO 图片拷贝
- IO--字符流操作五种方式及字节流的四种方式+图谱
- 复制图片的四种方式
- IO流文件的拷贝
- java数组四种拷贝方式
- Java:io流写入文件的四种实现方式的效率对比
- 拷贝图片三种流方式
- 如何利用IO拷贝图片
- java中文件IO之图片的拷贝解析
- cocos网络切换通知
- 正则 日期
- Android学习小记----监听电量的变化(不能静态注册的广播)
- shell脚本基础demo
- TensorFlow中的SWIG实现Python调用C/C++代码
- IO流拷贝图片的四种方式
- How tomcat works——2 一简单的Servlet容器
- Android博客地址
- 【C语言】 leetcode 453. Minimum Moves to Equal Array Elements
- git提交代码到远程仓库遇到的问题并且关于ssh密钥的研究
- Gradle配置
- Android管理WIFI
- 算法竞赛入门经典第二版(刘汝佳)第一章思考题
- struts2.5.5+hibernate5.2.6+spring4.3.4登陆案例