Input file with spaces, new line breaks and other things. It has only numbers, how to convert it into a one-dimensional array from int? I tried through the regulars, all the same between the numbers there are characters of transfer to a new line.
- oneComplement the question with an example of data and what you have already done. - simpleCode
|
1 answer
Can be read from file using Scanner
public static void main(String[] args) throws Exception { Scanner scanner = new Scanner(Paths.get("path to file")); List<Integer> list = new ArrayList<>(); while (scanner.hasNextInt()) { list.add(scanner.nextInt()); } int arr[] = new int [list.size()]; for (int i = 0; i < list.size(); i++) { arr[i] = list.get(i); } } |