u012441759
玲听Lynda
2015-09-05 01:15

java中读取文件提示找不到指定路径???

  • exception
  • java

import java.io.File;
import java.io.FileReader;
import java.io.FileWriter;

public class FileCombine {

public static void main(String[] args) throws Exception {
    // TODO Auto-generated method stub
    FileManager afilemg = new FileManager("a.txt",new char[]{'\n'});
    FileManager bfilemg = new FileManager("b.txt",new char[]{'\n',' '});
    FileWriter cfile = new FileWriter("c.txt");
    String aword = null;
    String bword = null;
    while((aword = afilemg.nextWord())!=null){
        cfile.write(aword+"\n");
        bword = bfilemg.nextWord();
        if(bword != null)
            cfile.write(bword+"\n");
    }
    while((bword = bfilemg.nextWord()) != null)
        cfile.write(bword);
    cfile.close();
}

}

class FileManager{
String[] words = null;
int pos = 0;
public FileManager(String filename, char[]separators)throws Exception{
File f = new File(filename);
FileReader reader = new FileReader(f);
char[] buf = new char[(int)f.length()];
int len = reader.read(buf);
reader.close();
String result = new String(buf,0,len);
String regex = null;
if(separators.length>1)
regex = ""+separators[0]+"|"+separators[1];
else regex = ""+separators[0];
words = result.split(regex);
}
public String nextWord(){
if(pos==words.length)
return null;
else return words[pos++];
}
}

Exception in thread "main" java.io.FileNotFoundException: a.txt (系统找不到指定的文件。)
at java.io.FileInputStream.open(Native Method)
at java.io.FileInputStream.(Unknown Source)
at java.io.FileReader.(Unknown Source)
at excises.FileManager.(FileCombine.java:35)
at excises.FileCombine.main(FileCombine.java:11)
请问这是什么问题???

  • 点赞
  • 回答
  • 收藏
  • 复制链接分享

9条回答