N
N
NikitaWeb2019-08-19 09:15:31
Java
NikitaWeb, 2019-08-19 09:15:31

An exception is thrown when it shouldn't. What is the problem?

The file contains data about RectButton (4 coordinates, state and text). You need to read them and create a new RectButton based on them

public static RectButton  readRectButtonFromTextFileSixLines(File file) throws IOException, WindowException {
        try (BufferedReader br = new BufferedReader(new InputStreamReader(new FileInputStream(file)))) {
            int[] array = new int[4];
            String state, text;
            array[0] = br.read();
            br.readLine();
            array[1] = br.read();
            br.readLine();
            array[2] = br.read();
            br.readLine();
            array[3] = br.read();
            br.readLine();
            state = br.readLine();
            text = br.readLine();
            return new RectButton(array[0], array[1], array[2], array[3], state, text);
        } catch (FileNotFoundException e) {
            throw new FileNotFoundException();
        } catch (UnsupportedEncodingException e) {
            throw new FileNotFoundException();
        } catch (IOException e) {
            throw new IOException();
        }
    }

But when creating an instance, an exception is thrown, although it shouldn't be
5d5a3e6b57d93684515912.png
. What could be the problem?

Answer the question

In order to leave comments, you need to log in

1 answer(s)
M
Mikhail Ketov, 2019-08-19
@NikitaWeb

String comparison in java is not done through == or !=, but through the String methodequals

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question