In Java, how would I convert an entire input file into one String
?
In other words, if I have an input file "test.in"
:
c++
java
python
test
then I want to create a String
containing "c++javapythontest"
.
I thought of something along the lines of
Scanner input = new Scanner(new File("test.in"));
while(input.hasNext()){
String test = test + input.nextLine();
}
but that doesn't seem to work.
Is there an efficient way to do this?