Good day. The problem when compiling java code below.
The essence of the program:
- it must read the file name from the console;
- read this file (the file contains integer values in a column, i.e., each new number from a new row);
write to the
ArrayListarray.import java.io.*; import java.util.ArrayList; public class Class1 { public static void main(String[] args) throws IOException { try { BufferedReader bufR = new BufferedReader(new InputStreamReader(System.in)); FileInputStream input = new FileInputStream(bufR.readLine()); ArrayList<Integer> ints = new ArrayList<>(); StringBuilder sbd = new StringBuilder(); while (input.available() > 0) { char ch = (char) input.read(); if (ch == '\n') { ints.add(new Integer(sbd.toString())); sbd.delete(0, sbd.length()); } else { sbd.append(ch); } } bufR.close(); input.close(); } catch (IOException e) { } } }
Problem in line:
ints.add(new Integer(sbd.toString())); But I do not know why. I tried parsing, it also does not work. Perhaps the problem is different, and this is only a consequence? I will be glad to any hint!
