Read file contents to string using commons-io?
import org.apache.commons.io.FileUtils; import java.io.File; import java.io.IOException; public class Main { public static void main(String[] args) { File file = new File("sample.txt"); String content = FileUtils.readFileToString(file); System.out.println("File content: " + content); } }