zoukankan      html  css  js  c++  java
  • 文件的复制和剪切功能,简单实现

    个人写的文件的复制方法和剪切方法,是一个初出茅庐的小猿猿,有什么缺点,请各位大神指出
    /**
    * * @param tarPath 把文件复制到那个路径 * @param sourcePath 复制文件的路径 * @throws IOException */ // 文件的复制功能 public void copyFile(String tarPath, String sourcePath) throws IOException { File tarFile = new File(tarPath); if(!tarFile.exists()){ tarFile.createNewFile(); } File sourceFile = new File(sourcePath); try { // 创建一个文件输入流 FileInputStream fis = new FileInputStream(sourceFile); // 输入流缓冲区 BufferedInputStream bis = new BufferedInputStream(fis); byte[] buffer = new byte[bis.available()]; bis.read(buffer); bis.close(); fis.close(); // 创建一个文件输出流 FileOutputStream fos = new FileOutputStream(tarFile); BufferedOutputStream bos = new BufferedOutputStream(fos); // 将数据写入输出流 bos.write(buffer); // 此处需要刷新 bos.flush(); bos.close(); } catch (FileNotFoundException e) { // TODO Auto-generated catch block e.printStackTrace(); } catch (IOException e) { // TODO Auto-generated catch block e.printStackTrace(); } } //删除文件(也可以当做复制完文件以后 ,剪切功能) /** * * @param sourcePath 要删除的文件路径 */ public void deleteFile(String sourcePath){ File tarFile = new File(sourcePath); if(tarFile.isFile()) tarFile.delete(); }
  • 相关阅读:
    SpringCloud五大组件
    js获取系统信息
    java深入
    java实现群头像合成
    .net读取上传apk文件的包名、软件名称、logo解决方法
    SignalR 跨域设置
    Html5 Video 实现方案
    JS 日期工具类-基于yDate
    图片下载本地缓存时间戳显示图片方法
    一个Notification 进度条插件(android,NJS实现,直接就可使用)
  • 原文地址:https://www.cnblogs.com/git-niu/p/6149866.html
Copyright © 2011-2022 走看看