by

Read file in Java

Efficient way to read file in Java using Files class
Copy Embed Code
<iframe id="embedFrame" style="width:600px; height:300px;"
src="https://www.snip2code.com/Embed/1618428/Read-file-in-Java?startLine=0"></iframe>
Click on the embed code to copy it into your clipboard Width Height
Leave empty to retrieve all the content Start End
import java.nio.file.Files; import java.nio.file.Paths; public static String readFile(String path) throws Exception { if (isNullOrEmpty(path)) { return ""; } return new String(Files.readAllBytes(Paths.get(path))); }
If you want to be updated about similar snippets, Sign in and follow our Channels

blog comments powered by Disqus