In Java, how would I convert an entire input file into one
Scanner input = new Scanner(new File("test.in"));
String test = test + input.nextLine();
To read file contents, discarding newline chars:
String contents = Files.lines(Paths.get"test.in")).collect(Collectors.joining());
I think you needed to test for
hasNextLine(), and your code's performance suffers from the creation of so many objects when you concatenate strings like that. If you changed your code to use a
StringBuilder, it would run much faster.