String fileContent = new Scanner(new File("D:sample.txt")) .useDelimiter("") .tokens() .reduce((s, r) -> s + r) .orElseThrow(() -> new IOException("Empty File"));