zoukankan      html  css  js  c++  java
  • java实现复制粘贴文件java


    实现将E:\itcast\creat.txt内容复制到Normal\out.txt(idea项目)中


    import java.io.FileInputStream;

    import java.io.FileOutputStream;
    import java.io.IOException;
    public class CopyDate {
    public static void main(String[] args) throws IOException {
    FileInputStream in=new FileInputStream("E:\itcast\creat.txt");//创建字节输入流对象
    FileOutputStream out=new FileOutputStream("Normal\out.txt");//创建字节输出流对象
          int len;
    while((len=in.read())!=-1){
    out.write(len);//一次读写一个字节
    }
    in.close();
    out.close();//一定记住关闭资源

    }
    }
    复制图片:
    import java.io.FileInputStream;
    import java.io.FileOutputStream;
    import java.io.IOException;
    public class CopyImg {
    public static void main(String[] args) throws IOException {
    FileInputStream in = new FileInputStream("E:\itcast\1.jpg");//将E盘下的图片地址给字节输入流对象In
    FileOutputStream out = new FileOutputStream("Gzy_BasicJava\newCopy.jpg");//字节输出流地址
    byte[] bytes = new byte[1024];
    int len ;
    while ((len = in.read(bytes)) != -1) {
    out.write(bytes,0,len);
    }
    in.close();//释放资源
    out.close();
    }
    }
     
  • 相关阅读:
    gil
    异步
    字符串 最长回文字串
    字符串 最长公共前缀
    数组 合并区间
    python 排序
    2021.9.3 阿里笔试AK贴
    SIP协议详解
    fiddler抓包各字段的含义
    常见的HTTP状态码列表
  • 原文地址:https://www.cnblogs.com/gzy918/p/13829280.html
Copyright © 2011-2022 走看看