兄弟 刚写的 还热乎着呢
给你参考,加上我刚才的思路,你想一下.
- package NoUseArea;
- import java.io.BufferedInputStream;
- import java.io.BufferedOutputStream;
- import java.io.File;
- import java.io.FileInputStream;
- import java.io.FileOutputStream;
- import java.io.IOException;
- public class text9 {
- public static void main(String[] args) throws IOException {
-
- File source = new File("D:\\downloads\\JAVA\\毕向东视频\\毕向东视频Java基础源代码Codes\\day01");
- File target = new File("D:\\myjava\\myself\\1");
-
- fileCheck(source,target);
- }
-
-
- public static void fileCheck(File source,File target) throws IOException{
- File[] files = source.listFiles();
- for(File file : files){
- if(file.isFile()){
- if(file.getName().endsWith(".java"))
- fileCopy(file,target);
- }else{
- fileCheck(source,target);
- }
- }
- }
-
- public static void fileCopy(File source,File target) throws IOException{
- String Name=source.getName().replace(".java", ".txt");
- File newTarget=new File(target,Name);
- BufferedInputStream bfis = new BufferedInputStream(new FileInputStream(source));
- BufferedOutputStream bfos = new BufferedOutputStream(new FileOutputStream(newTarget));
-
- int len = 0;
- while((len=bfis.read())!=-1){
- bfos.write(len);
- }
-
- bfis.close();
- bfos.close();
- }
- }
复制代码 |