Created
August 11, 2021 10:16
-
-
Save LemonNekoGH/70e55c32fd383607fed96fbf1389cbc8 to your computer and use it in GitHub Desktop.
把指定文件夹中的所有指定后缀的文件转移到一个文件中(GC引入第三方库必备)
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import java.io.File; | |
import java.io.BufferedInputStream; | |
import java.io.BufferedOutputStream; | |
import java.io.FileInputStream; | |
import java.io.FileOutputStream; | |
public class TransferAllIntoOne { | |
public static void main(String[] args) throws Throwable { | |
File file = new File("."); | |
File to = new File("./Index.js"); | |
iterateAllFile(file, to); | |
} | |
public static void iterateAllFile(File file,File to) throws Throwable { | |
if (file.isDirectory()) { | |
File[] childrens = file.listFiles(); | |
for (File child : childrens) { | |
iterateAllFile(child, to); | |
} | |
} else { | |
if (file.getName().endsWith(".ts")) { | |
BufferedInputStream bis = new BufferedInputStream(new FileInputStream(file)); | |
BufferedOutputStream bos = new BufferedOutputStream(new FileOutputStream(to, true)); | |
bos.write(bis.readAllBytes()); | |
bos.close(); | |
bis.close(); | |
} | |
} | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment