类文件方法toPath()的NoSuchMethodError [英] NoSuchMethodError for Class File Method toPath()

查看:101
本文介绍了类文件方法toPath()的NoSuchMethodError的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在尝试使用以下代码将StandardQuestions.csv文件复制到新文件名:

I'm attempting to copy the file StandardQuestions.csv to a new filename with the following code:

String standardQuestions = "StandardQuestions.csv";
if(new File(standardQuestions).exists()){
    try{
        Path source = new File(standardQuestions).toPath();
        Path dest = new File(filename).toPath();
        Files.copy(source,dest);
    }
     catch(java.io.IOException e){JOptionPane.showMessageDialog(this,"Error: Input/Output exception.");}
}

我在行Path source = new File(standardQuestions).toPath();上引发了一个错误,我的错误消息是NoSuchMethodError,在类File中找不到toPath方法. File类怎么可能没有这种方法?该程序可以在3-4台计算机上正常运行,但是对于一个用户,它总是会引发此错误.知道是什么原因造成的吗?回答这个问题是否需要其他信息?

I get an error thrown on the line Path source = new File(standardQuestions).toPath(); My error message is NoSuchMethodError, method toPath not found in class File. How could the File class not have this method? The program runs correctly on 3-4 machines, but for one user, it always throws this error. Any idea what's causing this? Is there any additional information needed to answer this question?

推荐答案

由于PathtoPath()是Java库中相对较新的添加(它们已在Java 7中添加),因此请确保您在所有计算机上都使用相同版本的Java.

Since Path and toPath() are relatively recent additions to the Java library (they've been added in Java 7), I'd make sure you are using the same version of Java across the machines.

这篇关于类文件方法toPath()的NoSuchMethodError的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
相关文章
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆