{:2_35:}有两个<>括号 是专门发代码的,发多少都不怕
- package test;
- import java.io.*;
- public class Test9{
-
- public static void main(String[] args)throws Exception{
- // File file=new File("D:"+File.separator+"javaClass");
- File file2=new File("D:"+File.separator+"javaTemp");
- // test(file,file2);
- test2(file2);
- }
- public static void test2(File file)throws Exception{
- if(!file.exists())
- throw new RuntimeException();
- File[] files=file.listFiles(new FilenameFilter(){
- public boolean accept(File dir,String name){
- return name.endsWith(".txt")||dir.isDirectory();
- }
- });
- for(File f:files){
- if(f.isDirectory()){
- test2(f);
- }else{
- int len=f.getName().lastIndexOf(".");
- System.out.println(f.renameTo(new File(f.getParent()+File.separator+""+f.getName().substring(0,len)+".java")));
-
- }
- }
- }
-
- public static void test(File file,File file2)throws Exception{
- if(!file.exists())
- throw new RuntimeException("源文件不存在!");
- if(!file2.exists()){
- file2.mkdir();
- }
-
- File[] files=file.listFiles(new FilenameFilter(){
- public boolean accept(File dir,String name){
- return name.endsWith(".java")||dir.isDirectory();
- }
- });
- for(File f:files){
- if(f.isDirectory()){
- File file22=new File(file2.getAbsolutePath()+""+File.separator+""+f.getName());
- file22.mkdir();
- test(f,file22);
- }else{
- BufferedInputStream bis=null;
- BufferedOutputStream bos=null;
-
- bis=new BufferedInputStream(new FileInputStream(f));
- int le=f.getName().lastIndexOf(".");
- String name=f.getName().substring(0,le);
- bos=new BufferedOutputStream(new FileOutputStream(file2.getAbsolutePath()+""+File.separator+""+name+".txt"));
-
- byte[] buff=new byte[1024];
- int len=-1;
- while(-1!=(len=bis.read(buff))){
- bos.write(buff,0,len);
- bos.flush();
- }
- bis.close();
- bos.close();
- }
- }
- }
- }
复制代码 |