E
E
Elzee2019-10-19 16:10:58
Java
Elzee, 2019-10-19 16:10:58

Unable to compile due to an error, why?

5dab0af24f2aa463834667.png

import java.io.*;

public class Solution {
    public static void main(String[] args) throws IOException {
        BufferedReader fileReader = new BufferedReader(new InputStreamReader(System.in));
        String f1 = fileReader.readLine();
        String f2 = fileReader.readLine();

        fileReader.close();
        BufferedReader reader = new BufferedReader(new FileReader(f1));
        BufferedWriter writer = new BufferedWriter(new FileWriter(f2));

        while (reader.ready()) {
            String[] numLineArr = reader.readLine().split(" ");

            for (String num : numLineArr) {
                long numbers = Long.parseLong(num);
                writer.write(numbers + " ");
            }
        }

        reader.close();
        writer.close();

    }
}

Answer the question

In order to leave comments, you need to log in

1 answer(s)
M
Maxim Moseychuk, 2019-10-19
@yourdreambtw

Everything compiles and even runs, do not invent.
The file whose name you want to enter into the console was not found. Hence the exception occurs. Which in more than detail painted the reason for you on a half-screen in red text, which you didn’t even bother to read on your own.
I'm afraid you shouldn't learn programming.

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question