So I’m using Java on a Linux machine and I currently am trying to read from stdin so that when I run “java Simulation more ~test/locationOfInput/test” it takes a stream of numbers and calculates values and prints them. However, my code is locking up when trying to read in the values and I have a check for empty files so I know it’s at least receiving the file. I currently have this code to read the stdin into an array
Scanner input = new Scanner(System.in); ArrayList<Integer> values = new ArrayList<Integer>(); while (input.hasNextInt()) { int i = input.nextInt(); values.add(i); }
The loop seems to be running infinitely and I’m not sure why. Am I misunderstanding how to read in from STDIN?
Advertisement
Answer
You need to use cat ~test/locationOfInput/test | java Simulation
to redirect the output properly.