玲听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
    关注

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

    评论

报告相同问题?

悬赏问题

  • ¥15 #MATLAB仿真#车辆换道路径规划
  • ¥15 java 操作 elasticsearch 8.1 实现 索引的重建
  • ¥15 数据可视化Python
  • ¥15 要给毕业设计添加扫码登录的功能!!有偿
  • ¥15 kafka 分区副本增加会导致消息丢失或者不可用吗?
  • ¥15 微信公众号自制会员卡没有收款渠道啊
  • ¥100 Jenkins自动化部署—悬赏100元
  • ¥15 关于#python#的问题:求帮写python代码
  • ¥20 MATLAB画图图形出现上下震荡的线条
  • ¥15 关于#windows#的问题:怎么用WIN 11系统的电脑 克隆WIN NT3.51-4.0系统的硬盘