【复制指定目录下的指定类型文件,并修改后缀名】
生活随笔
收集整理的這篇文章主要介紹了
【复制指定目录下的指定类型文件,并修改后缀名】
小編覺得挺不錯的,現在分享給大家,幫大家做個參考.
package com.companyname.common.test;import java.io.*;/*** @Description* @Author Created by shusheng.* @Email shusheng@yiji.com* @Date 2018/12/2*/
public class CopyFolderDemo {public static void main(String[] args) throws IOException {// 封裝目錄File srcFolder = new File("E:\\【GIT-FILES】\\yix\\yix-common\\src\\main\\java\\com\\yiji\\yix\\common\\utils");// 封裝目的地File destFolder = new File("E:\\test");// 如果目的地目錄不存在,就創建if (!destFolder.exists()) {destFolder.mkdirs();}// 獲取該目錄下的java文件的File數組File[] fileArray = srcFolder.listFiles(new FilenameFilter() {@Overridepublic boolean accept(File dir, String name) {return new File(dir, name).isFile() && name.endsWith(".java");}});// 遍歷該File數組,得到每一個File對象,并復制到目標文件夾for (File file : fileArray) {String name = file.getName();String newName = name.replace(".java", ".jad");File newFile = new File(destFolder, newName);copyFile(file, newFile);}}public static void copyFile(File file, File newFile) throws IOException {BufferedInputStream bis = new BufferedInputStream(new FileInputStream(file));BufferedOutputStream bos = new BufferedOutputStream(new FileOutputStream(newFile));byte[] bytes = new byte[1024];int len = 0;while ((len = bis.read(bytes)) != -1) {bos.write(bytes, 0, len);}bis.close();bos.close();}}
?
轉載于:https://www.cnblogs.com/zuixinxian/p/10087018.html
總結
以上是生活随笔為你收集整理的【复制指定目录下的指定类型文件,并修改后缀名】的全部內容,希望文章能夠幫你解決所遇到的問題。
- 上一篇: 软件工程三大势力
- 下一篇: tensorflow-Inception