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?
testis undefined, so what is there to add to?FileInputStream fis=new FileInputStream("test.in"); byte[] byteArray=new byte[fis.availble()]; fis.read(byteArray,0,byteArray.length); String str=new String(byteArray);