Skip to content

Instantly share code, notes, and snippets.

@friek
Created July 1, 2015 09:12
Show Gist options
  • Select an option

  • Save friek/4ecc591f1fea6cbf2586 to your computer and use it in GitHub Desktop.

Select an option

Save friek/4ecc591f1fea6cbf2586 to your computer and use it in GitHub Desktop.
One liner for reading a file in Java.
package file;
import java.io.IOException;
import java.nio.charset.Charset;
import java.nio.file.Files;
import java.nio.file.Paths;
public class FileReader
{
public static void main(String[] args) throws IOException
{
System.out.print(new String(Files.readAllBytes(Paths.get("/etc/passwd")), Charset.forName("UTF-8")));
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment