zoukankan      html  css  js  c++  java
  • 编写一个程序,把指定目录下的所有的带.java文件都拷贝到另一个目录中,拷贝成功后,把后缀名是.java的改成.txt。

    package example;
    
    import java.io.*;
    
    
    public class Test {
        public static void main(String[] args) throws IOException {
            File file1=new File ("F:"+File.separator+"src");
            copyAndRename(file1);
        }
    
        private static void copyAndRename(File file1) throws IOException {
            File[] fi=file1.listFiles(new SuffixFilter());
            String filename="F:"+File.separator+"src2";
            byte[] buf=new byte[1024];
            int len;
            for(File f:fi){
                String fname=f.getName();
                BufferedInputStream bis=new BufferedInputStream(new FileInputStream(f));
                BufferedOutputStream bos=new BufferedOutputStream(new FileOutputStream(filename+File.separator+fname));
                while((len=bis.read(buf))!=-1){
                    bos.write(buf,0,len);
                }
                 bis.close();
                 bos.close();
               File f2=new File(f.getAbsolutePath());
               fname=fname.replace(".java", ".txt"); 
               File f3=new File("F:"+File.separator+"src"+File.separator+fname);
               f2.renameTo(f3);
            }
            
        }
    }
    
    class SuffixFilter implements FilenameFilter{
    
        public boolean accept(File dir, String name) {
            
            return name.endsWith(".java");
        }
        
    }

    来不及注释了,睡觉,困死了

  • 相关阅读:
    [转]windows7远程桌面连接失败:发生身份验证错误。要求的函数不受支持
    SNMP协议学习笔记
    Sublime for MacOS 使用技巧
    Git常用操作
    罗技K380连接Win10(MacBookPro双系统)系统失败
    Git知识点汇总
    开发工作中提高效率的一些方式
    css
    IO多路复用
    进程
  • 原文地址:https://www.cnblogs.com/xurui1995/p/5211665.html
Copyright © 2011-2022 走看看