您的位置:首页 > 编程语言 > Java开发

[Java] 通过文件流拷贝文件

2016-04-13 13:05 399 查看
package test.stream;

import java.io.FileInputStream;
import java.io.FileNotFoundException;
import java.io.FileOutputStream;
import java.io.IOException;
/**
* 通过文件流拷贝文件
* @author Frost.Yen
* @E-mail 871979853@qq.com
* @date 2016年4月13日
*/
public class TestStream02 {
public static void main(String[] args) {
FileInputStream fis = null;
FileOutputStream fos = null;

try {
fis = new FileInputStream("E:\\JAVA\\Examples\\To Learn\\src\\test\\stream\\1.jpg");
fos = new FileOutputStream("E:\\JAVA\\Examples\\To Learn\\src\\test\\stream\\a.jpg");
byte[] buf = new byte[1024];
int len = 0;
while((len=fis.read(buf))>=0){
fos.write(buf, 0, len);
}
} catch (FileNotFoundException e) {
e.printStackTrace();
} catch (IOException e) {
e.printStackTrace();
} finally {
try {
if(fis!=null) fis.close();
} catch (IOException e) {
e.printStackTrace();
}
try {
if(fos!=null) fos.close();
} catch (IOException e) {
e.printStackTrace();
}
}

}
}
内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息
标签: