Read from URI wrapped in Path using buffered reader - Java File Path IO

Java examples for File Path IO:Path

Description

Read from URI wrapped in Path using buffered reader

Demo Code

import java.io.BufferedReader;
import java.io.IOException;
import java.net.URI;
import java.net.URISyntaxException;
import java.nio.charset.Charset;
import java.nio.file.Files;
import java.nio.file.Paths;

public class Main {
  public static void main(String[] args) {
    try (BufferedReader inputReader = Files.newBufferedReader(Paths.get(new URI("file:///C:/home/docs/users.txt")),
        Charset.defaultCharset())) {
      String inputLine;/*from   w w w .jav  a  2 s  .  c  o m*/
      while ((inputLine = inputReader.readLine()) != null) {
        System.out.println(inputLine);
      }
    } catch (IOException | URISyntaxException ex) {
      ex.printStackTrace();
    }

  }
}

Related Tutorials