本帖最后由 张雪磊 于 2012-7-28 08:50 编辑
package com.itheima;
import java.io.*;
/*
需求: 编写一个程序,将d:\java 目录下的所有.java 文件复制到d:\jad 目录下,
并将原来文件的扩展名从.java 改为.jad
*/
public class Test9 {
/**
* @param args
*/
public static void main(String[] args) throws IOException{
// TODO Auto-generated method stub
File dir=new File("d:\\java");
searchFile(dir);
}
public static void searchFile(File dir)throws IOException{
File[] files = dir.listFiles();
for(File file:files){
if(file.isDirectory())
searchFile(file);
else{
if(file.getName().endsWith(".java")){
BufferedReader bufr =
new BufferedReader(new FileReader(file.getName()));
String[]arr=file.getName().split("\\.");
BufferedWriter bufw=
new BufferedWriter(new FileWriter("d:\\jad\\"+arr[0]+".jad"));
String line=null;
while((line=bufr.readLine())!=null){
bufw.write(line);
bufw.flush();
}
bufw.close();
bufr.close();
}
}
}
}
}
错误信息:
Exception in thread "main" java.io.FileNotFoundException: BufferedDemo.java (系统找不到指定的文件。)
at java.io.FileInputStream.open(Native Method)
at java.io.FileInputStream.<init>(Unknown Source)
at java.io.FileInputStream.<init>(Unknown Source)
at java.io.FileReader.<init>(Unknown Source)
at com.itheima.Test9.searchFile(Test9.java:31)
at com.itheima.Test9.main(Test9.java:19)
|
|