首页 > 解决方案 > 如何修复 IOException

问题描述

我为此尝试了几个文件路径,但即使文件存在,仍然得到 IOException 这是我的代码:

public static void main(String[] args) {
        String [] letters = {"a", "b"};
        Object ob = new object(letters);
        ob.training(new File("C:/Users/Dell/Desktop/train.txt"));
        ob.classify(new File("C:/Users/Dell/Desktop/data.txt"), new File("C:/Users/Dell/Desktop/classify.txt"));
    }

我在训练和分类方法中使用了 throws 语句,但它仍然会要求我在 main 方法中使用 throws 语句,当我这样做时它不会运行。或者它会运行但根本没有通过名为 CodeGrade 的程序的编译测试。谁能帮我解决这个问题?

标签: java

解决方案


试着看这里

main方法抛出异常是什么意思?

但如果你使用 Windows,也许这就是你的解决方案:

new File("C://Users//Dell//Desktop//train.txt"))

推荐阅读