So for an assignment at school I am required to make a program in java that manages some students at a college, the user may invoke a number of function, but I started by testing ‘add’.
My prof recommends that I use input redirection, because I can easily test the program over and over, without much typing. Now here is the issue.
echo `< input.txt`
add Student Name 123 Street,City,Province,Postal Code q
#Input rediraction ate my newlines
cat input.txt
add
Student Name
Street,City,Province,Postal Code
q
#What I actually want to run
java -cp . TestCollege < input.txt #fail horribly
As you can see bash removes the newline characters I use to delimit my input, and thus my program crashes, because when you run it in interactive mode, Scanner.getLine() just blocks until input occurs.
Any idea how I can give my program the input with the newlines, it seems to work fine in windows “cmd” but not in “bash”.
Could you try wrapping
BufferedInputStreamaroundSystem.in, because it can handle both cases:\r\nand\n; and I think that’s where your problem lies.Or rather, call
useDelimiter(System.getProperty("line.separator"))onScanner.