In Java, if you know for certain a file is very small, you can use readBytes() method to read the content in one go instead of read it line by line or using buffer.
readBytes()
Process the lines inside the loop instead of after it. If you really need the file in a variable:
var=$(