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)
作者: 吴立杰 时间: 2012-7-27 21:04
import java.io.*;
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));//楼主这个地方错了,它要读的这个文件已经知道地址了,就不需要告诉它了
String[]arr=file.getName().split("\\.");
BufferedWriter bufw=
new BufferedWriter(new FileWriter("d:\\txt\\"+arr[0]+".txt"));