zoukankan      html  css  js  c++  java
  • 将一个文件保存在另一个路径下,并重命名

    import java.io.*;
    import java.util.Date;

    public class BackTest {
    static int BUFFER_SIZE = 1024;
    public static void main(String[] args) {
    int len=0;
    String fileName = "E:\\a.txt";
    String path = "E:\\a";
    System.out.println("保存图像方法");
    String latterpart= fileName.substring(fileName.lastIndexOf( "." ));
    String imagePath=path+"\\"+new Date().getTime()+latterpart;
    System.out.println("保存好的图像的路径为"+imagePath);

    String imageName=imagePath.substring(imagePath.lastIndexOf( "\\" )+1);
    File myFile = new File("E:\\a.txt");
    FileOutputStream fos;
    try {
    fos = new FileOutputStream(imagePath);
    FileInputStream fis=new FileInputStream(myFile);
    byte[] buffer=new byte[BUFFER_SIZE];
    while((len=fis.read(buffer))>0){
    fos.write(buffer,0,len);
    }
    } catch (FileNotFoundException e) {
    // TODO Auto-generated catch block
    e.printStackTrace();
    } catch (IOException e) {
    // TODO Auto-generated catch block
    e.printStackTrace();
    }

    }
    }

    写的挺乱的,先粘贴上,日后在修改一下。

  • 相关阅读:
    和大家一起了解Windows Server 2016 License许可证授权方式
    centos的cockpit安装使用
    Nscan-20150223
    JexBoss-20170328
    InsightScan-20150320
    Clusterd-20151119
    BBScan-20200419
    Astra-20190405
    为什么计算机计算时间要从1970年开始
    Appium环境搭建
  • 原文地址:https://www.cnblogs.com/wrh526/p/2200626.html
Copyright © 2011-2022 走看看