基本实现
    该实现方法利用缓冲容器(字节数组flush)实现分段输入输出
    其他方法:不采用缓冲容器而是一个字节一个字节地输入输出

    1. import java.io.*;
    2. public class IPS {
    3. String Iurl, Ourl;
    4. File Isrc, Osrc;
    5. byte[] flush = new byte[1024];//缓冲容器
    6. int len = -1;//辅助变量,显示缓冲容器当前的长度
    7. //int temp;
    8. InputStream Is = null;
    9. OutputStream Os = null;
    10. //构造器,获取输入源与输出目标
    11. public IPS(String Iurl, String Ourl){
    12. this.Iurl = Iurl;
    13. this.Ourl = Ourl;
    14. }
    15. //具体执行
    16. public void Operate(){
    17. try {
    18. //确定源
    19. Isrc = new File(Iurl);//输入源
    20. Osrc = new File(Ourl);//输出目标
    21. //确定流
    22. Is = new FileInputStream(Isrc);
    23. Os = new FileOutputStream(Osrc);
    24. //操作
    25. while((len = Is.read(flush)) != -1){
    26. Os.write(flush,0,len);
    27. Os.flush();
    28. }
    29. } catch (IOException e) {
    30. e.printStackTrace();
    31. }finally {
    32. //关闭流
    33. try {
    34. Is.close();
    35. Os.close();
    36. } catch (IOException e) {
    37. e.printStackTrace();
    38. }
    39. }
    40. }
    41. }

    主类

    1. public class Main {
    2. public static void main(String[] args){
    3. IPS a = new IPS("C:\\Users\\DaluxC\\Desktop\\新建文件夹δ\\u.png", "C:\\Users\\DaluxC\\Pictures\\Saved Pictures\\u.png");
    4. a.Operate();
    5. }
    6. }