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


     1 package test.stream;
     2 
     3 import java.io.FileInputStream;
     4 import java.io.FileNotFoundException;
     5 import java.io.FileOutputStream;
     6 import java.io.IOException;
     7 /**
     8  * 通过文件流拷贝文件
     9  * @author Frost.Yen
    10  * @E-mail 871979853@qq.com
    11  * @date 2016年4月13日
    12  */
    13 public class TestStream02 {
    14     public static void main(String[] args) {
    15         FileInputStream fis = null;
    16         FileOutputStream fos = null;
    17         
    18         try {
    19             fis = new FileInputStream("E:\JAVA\Examples\To Learn\src\test\stream\1.jpg");
    20             fos = new FileOutputStream("E:\JAVA\Examples\To Learn\src\test\stream\a.jpg");
    21             byte[] buf = new byte[1024];
    22             int len = 0;
    23             while((len=fis.read(buf))>=0){
    24                 fos.write(buf, 0, len);
    25             }
    26         } catch (FileNotFoundException e) {
    27             e.printStackTrace();
    28         } catch (IOException e) {
    29             e.printStackTrace();
    30         } finally {
    31             try {
    32                 if(fis!=null) fis.close();
    33             } catch (IOException e) {
    34                 e.printStackTrace();
    35             }
    36             try {
    37                 if(fos!=null) fos.close();
    38             } catch (IOException e) {
    39                 e.printStackTrace();
    40             }
    41         }
    42         
    43     }
    44 }
  • 相关阅读:
    webIDE 第二篇博文
    前端第一天
    记昨天
    入职第四天
    入职第二天
    linux常用命令,自己总结
    一切从头开始
    在服务器上搭建SVN
    Dynamic CRM 365学习历程--JS
    Dynamic CRM 365学习历程--有关CRM的学习过程种需要注意的事项
  • 原文地址:https://www.cnblogs.com/frost-yen/p/5386749.html
Copyright © 2020-2023  润新知