玲听Lynda 2015-09-05 01:15 采纳率: 33.3%
浏览 5023

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)
请问这是什么问题???

  • 写回答

10条回答 默认 最新

  • bdmh 移动开发领域优质创作者 2015-09-05 01:26
    关注

    把你文件的具体路径打印出来,看看是否正确,是否有特殊符号在里面等等

    评论

报告相同问题?

悬赏问题

  • ¥50 成都蓉城足球俱乐部小程序抢票
  • ¥15 yolov7训练自己的数据集
  • ¥15 esp8266与51单片机连接问题(标签-单片机|关键词-串口)(相关搜索:51单片机|单片机|测试代码)
  • ¥15 电力市场出清matlab yalmip kkt 双层优化问题
  • ¥30 ros小车路径规划实现不了,如何解决?(操作系统-ubuntu)
  • ¥20 matlab yalmip kkt 双层优化问题
  • ¥15 如何在3D高斯飞溅的渲染的场景中获得一个可控的旋转物体
  • ¥88 实在没有想法,需要个思路
  • ¥15 MATLAB报错输入参数太多
  • ¥15 python中合并修改日期相同的CSV文件并按照修改日期的名字命名文件