复制图片的四种方式
来源:互联网 发布:竞争学习算法 编辑:程序博客网 时间:2024/04/28 13:50
复制图片的四种方式:
import java.io.BufferedInputStream;
import java.io.BufferedOutputStream;
import java.io.File;
import java.io.FileInputStream;
import java.io.FileNotFoundException;
import java.io.FileOutputStream;
import java.io.IOException;
/*
* 复制图片
* 分析:
* 复制数据,如果我们知道用记事本打开并能够读懂,就用字符流,否则用字节流
* 通过该原理,我们知道我们应该采用字节流更方便些
* 而字节流有4种方式,所以做这个题目我们有4中方式,推荐掌握第4中方式
* 数据源:
* e:\\照片.jpg -- FileInputStream -- BufferedInputStream
* 目的地:
* f:\\照片1.jpg -- FileOutputStream -- BufferedOutputStream
*/
public class CopyImage {
publicstatic void main(String[] args) throws IOException {
//TODO Auto-generated method stub
//可以使用字符串作为路径也可以使用File对象作为参数
FilesrcFile = new File("照片.jpg"); //c:\\照片.jpg
FiledesFile = new File("照片1.jpg");
// method1(srcFile,desFile);
// method2(srcFile,desFile);
// method3(srcFile,desFile);
method4(srcFile,desFile);
}
//字节缓冲流一次读写一个数组
publicstatic void method4(File srcFile, File desFile) throws IOException {
//TODO Auto-generated method stub
BufferedInputStreambis = new BufferedInputStream(new FileInputStream(srcFile));
BufferedOutputStreambos = new BufferedOutputStream(new FileOutputStream(desFile));
byte[]bys = new byte[1024];
intlen = 0;
while((len= bis.read(bys)) != -1){
bos.write(bys,0,len);
}
bos.close();
bis.close();
}
//字节缓冲流一次读写一个字节
publicstatic void method3(File srcFile, File desFile) throws IOException {
//TODO Auto-generated method stub
BufferedInputStreambis = new BufferedInputStream(new FileInputStream(srcFile));
BufferedOutputStreambos = new BufferedOutputStream(new FileOutputStream(desFile));
intby = 0;
while((by= bis.read()) != -1){
bos.write(by);
}
bos.close();
bis.close();
}
//基本字节流一次读写一个字节数组
publicstatic void method2(File srcFile, File desFile) throws IOException {
//TODO Auto-generated method stub
FileInputStreamfis = new FileInputStream(srcFile);
FileOutputStreamfos = new FileOutputStream(desFile);
byte[]bys = new byte[1024];
intlen = 0;
while((len= fis.read(bys)) != -1){
fos.write(bys,0,len);
}
fos.close();
fis.close();
}
//基本字节流一次读写一个字节
publicstatic void method1(File srcFile, File desFile) throws IOException {
//TODO Auto-generated method stub
FileInputStreamfis = new FileInputStream(srcFile);
FileOutputStreamfos = new FileOutputStream(desFile);
intby = 0;
while((by= fis.read()) != -1){
fos.write(by);
}
fos.close();
fis.close();
}
}
- 复制图片的四种方式
- IO流:复制图片的四种方式实现
- 复制文本的五中方式与复制图片的四种方式
- 四种方式实现文件的复制
- js 复制文本的四种方式
- java 复制 的四种实现方式 及其比较
- IO流_复制图片的4种方式案例
- javaIO流之字节流的四种方式复制文件方式总结
- IO流拷贝图片的四种方式
- iOS中对图片拉伸的四种方式
- 复制图片的4种方式(copy图片只能用字节流对象)
- 使用字节流复制文件的四种方式以及效率比较
- Win8 图片的四种绑定方式 --- 图片的前后台数据绑定
- 复制文本的四种方法
- java复制数组的四种方法
- 数组的四种复制方法
- TensorFLow 读取图片1:初探四种从文件读取的方式
- nocache的四种方式
- 消息队列( MQ )
- 文件复制的5中方式
- Unity3D占用内存太大的解决方法
- 初学js插入节点appendChild insertBefore使用方法
- HDU1164 Eddy's research I
- 复制图片的四种方式
- hrbust/哈理工oj 1877 区间【水题】
- 把ArrayList集合中的字符串内容写到文本文件中
- Opencv学习笔记:搭建opencv2.4.9+openGL+QT5.6+vs2013
- 用eclipse开发时,新建java文件自动生成注释
- iOS:UIWebView
- OpenJDK Runtime Environment (IcedTea6 1.13.10) (rhel-1.13.10.0.el6_7-x86_64) OpenJDK 64-Bit Server V
- 满满的干货:推荐提升 Android 性能的建议
- allegro Disable custom colors is enabled