zoukankan      html  css  js  c++  java
  • 实现图片的拷贝案例演示

    /**
     * 实现图片的拷贝
     * 注意:用的是文件字节流 
     */
    package com.test4;
    import java.io.*;
    public class Demo12_4 {

    /**
    * @param args
    */
    public static void main(String[] args) {
    // TODO Auto-generated method stub
    //创建输入流
    FileInputStream fis=null;
    //创建输出流
    FileOutputStream fos=null;
    try {
    //用于图片也可以
    fis= new FileInputStream("d:\a.jpg");
    fos= new FileOutputStream("e:\a.jpg");
    // 用于文本文件也可以
    fis= new FileInputStream("d:\ss.txt");
    fos= new FileOutputStream("e:\ss.txt");
    byte buf[]=new byte[1024];
    //循环读取
    int n=0;//记录实际读取到的字节数
    //循环读取
    while((n=fis.read(buf))!=-1)
    {
    //输出到指定文件
    fos.write(buf);
    System.out.println("文件已经完成复制");
    }
    } catch (Exception e) {
    // TODO Auto-generated catch block
    e.printStackTrace();
    }finally{
    //关闭文件流
    try {
    fis.close();
    fos.close();
    } catch (IOException e) {
    // TODO Auto-generated catch block
    e.printStackTrace();
    }
    }
    }

    }

  • 相关阅读:
    Luncence .Net 使用
    Quartz 使用
    asp.net mvc 部分视图加载区别
    C学习笔记-内存管理
    C学习笔记-内存管理
    C学习笔记-结构体
    C学习笔记-结构体
    C学习笔记-指针
    C学习笔记-指针
    dll的封装和使用
  • 原文地址:https://www.cnblogs.com/toge/p/6114728.html
Copyright © 2011-2022 走看看