简体   繁体   English

Java 保存 ArrayList 错误

[英]Java Saving ArrayList error

Hello this is my code eclipse is telling me the hire ArrayList needs to be an int and I want to print the toString() method in hire class so I can print everything in the array你好,这是我的代码 eclipse 告诉我租用ArrayList需要是一个int ,我想在租用类中打印toString()方法,以便我可以打印数组中的所有内容

    public static void save() {
    try {

        File file = new File("D:/Assignment/filename.txt");

        // If file does not exists then create it
        if (!file.exists()) {
            file.createNewFile();
        }

        FileWriter fw = new FileWriter(file.getAbsoluteFile());
        BufferedWriter bw = new BufferedWriter(fw);
        for(Hire hire:HireList)
        bw.write(hire);
        bw.close();

        System.out.println("Done");

    } catch (IOException e) {
        e.printStackTrace();
    }
}

If you want to write the hire.toString() , simply use this :如果你想写hire.toString() ,只需使用这个:

bw.write(hire.toStrig());

else Javac can't know if your calling bw.write(int) or bw.write(String) or other ...否则 Javac 无法知道您的调用是bw.write(int)还是bw.write(String)或其他...

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM