Advertisement
xplt

Java NIO File Reading

Jan 6th, 2015
267
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Java 0.37 KB | None | 0 0
  1. String filePath = "path/to/file.txt";
  2. Path input = Paths.get(filePath);
  3.  
  4. try (InputStream in = Files.newInputStream(input);
  5.     BufferedReader reader = new BufferedReader(new InputStreamReader(in))) {
  6.  
  7.     String line = null;
  8.     while ((line = reader.readLine()) != null) {
  9.         LOG.info(line);
  10.     }
  11. } catch (IOException e) {
  12.     LOG.error("File not found", e);
  13. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement