Keane_T 2015-04-22 14:24 采纳率: 25%
浏览 2930

Java filenotfoundexception问题,路径找不到。。。

提示我路径未找到,文件名是自己键入的,代码如下:
public class CSVParser extends ConsoleProgram {

public void run(){
    ArrayList<String> result = new ArrayList<String>();
    String filename = openfile("Enter the filename :");
    int columnIndex = readInt("Enter the column index :");
    result = extractColumn(filename,columnIndex);
    println(result);    
}
//读取文件,若文件不存在则提示,重新键入文件名
private String openfile(String prompt){
    BufferedReader rd = null;
    while(rd==null){
        try{
            String name = readLine(prompt);
            rd = new BufferedReader(new FileReader(name));          
        }catch(IOException e){
            println("bad file.The file doesn't exist.");
        }
    }
    return getName();       

}
//根据文件名和所要获取的列数输出该列所有内容
private ArrayList extractColumn(String filename, int columnIndex) {
ArrayList result = new ArrayList();
try {

        BufferedReader rd = new BufferedReader(new FileReader(filename));   
        String line="";
        while((line = rd.readLine()) != null){              
            String str = (fieldsIn(line).get(columnIndex-1));           
            result.add(str);            
            }rd.close();
}catch (IOException e){ 
    e.printStackTrace();
    throw new RuntimeException(e);
        }               
    return result;
}

}

  • 写回答

2条回答

  • 毕小宝 博客专家认证 2015-04-23 00:44
    关注

    工具是最公正的,有异常还是说明程序本身有问题。你检查下输入的文件路径是否正确。文件路径中统一用“/"。
    祝好!

    评论

报告相同问题?

悬赏问题

  • ¥15 如何在scanpy上做差异基因和通路富集?
  • ¥20 关于#硬件工程#的问题,请各位专家解答!
  • ¥15 关于#matlab#的问题:期望的系统闭环传递函数为G(s)=wn^2/s^2+2¢wn+wn^2阻尼系数¢=0.707,使系统具有较小的超调量
  • ¥15 FLUENT如何实现在堆积颗粒的上表面加载高斯热源
  • ¥30 截图中的mathematics程序转换成matlab
  • ¥15 动力学代码报错,维度不匹配
  • ¥15 Power query添加列问题
  • ¥50 Kubernetes&Fission&Eleasticsearch
  • ¥15 報錯:Person is not mapped,如何解決?
  • ¥15 c++头文件不能识别CDialog