import java.io.IOException; import java.nio.file.Files; import java.nio.file.Paths; public static void main(String[] args) throws IOException { String content = new String(Files.readAllBytes(Paths.get("duke.java"))); String content=new String(Files.readAllBytes(file.toPath()),Charset.forName("UTF-8"));//specify the charset }