通过文件流复制图片
来源:互联网 发布:js 去掉数组重复元素 编辑:程序博客网 时间:2024/05/22 00:50
- import java.io.BufferedOutputStream;
- import java.io.File;
- import java.io.FileInputStream;
- import java.io.FileNotFoundException;
- import java.io.FileOutputStream;
- import java.io.IOException;
-
- public class ImageCopier {
-
- public static void main(String args[]) throws Exception{
-
-
-
- String srcUrl = "D:/My Documents/temp/p1.jpg";
-
-
- String tarUrl = "D:/My Documents/temp/p2.jpg";
- ioImage(srcUrl, tarUrl);
- }
-
-
-
-
-
-
- public static void ioImage(String srcUrl,String tarUrl){
-
- try {
-
-
- FileInputStream finput = new FileInputStream(new File(srcUrl));
-
-
- FileOutputStream foutput = new FileOutputStream(new File(tarUrl));
- BufferedOutputStream bos = new BufferedOutputStream(foutput);
-
- int b ;
- while(true) {
- if(finput.available()<1024){
-
- while((b=finput.read())!=-1){
-
- bos.write(b);
- }
- break;
- }else{
-
- b=finput.read();
- bos.write(b);
- }
- } finput.close();
- bos.close();
- foutput.close();
-
- } catch (FileNotFoundException e) {
-
- e.printStackTrace();
- } catch (IOException e) {
-
- e.printStackTrace();
- }
-
- }
- }