title: Java Relative path with URI
body: <p>The code below reads a local file.</p>
  
  <pre><code>final String filepath= "my/path/to/file.txt";
  
  try (BufferedReader reader = Files.newBufferedReader(Paths.get(filepath))){
      System.out.println("First line : "+reader.readLine());
  }
  </code></pre>
  
  <p>However, I want the exact equivalent but using URI. So my new code is as follow: </p>
  
  <pre><code>final String filepath= "file:///my/path/to/file.txt";
  
  try (BufferedReader reader = Files.newBufferedReader(Paths.get(new URI(filepath)))){
      System.out.println("First line : "+reader.readLine());
  }
  </code></pre>
  
  <p>And this is working well when <code>filepath</code> is an absolute path. But I want this to work even with a relative path (like in the first code).</p>
  
  <p>How can I do that ?</p>
  
  <p>EDIT : </p>
  
  <p>The solution I use is to use 'normal' path when I need local relative path, and URI in other cases (absolute path or remote).</p>
  
  <p>So my code is like that : </p>
  
  <pre><code>final String filepath= "my/path/to/file.txt"; // or "file:///my/path/to/file.txt";
  final URI uri = new URI(filepath);
  final Path path;
  
  if(uri.getScheme()!=null) {
      path = Paths.get(uri);
  }else {
      path = Paths.get(filepath);
  }
  
  try (BufferedReader reader = Files.newBufferedReader(path)){
      System.out.println("First line : "+reader.readLine());
  }
  </code></pre>
  
  <p>It's not really pretty but the work is done. If there is a better solution I am still open to it.</p>