title: Reading HDFS and local files in Java
body: <p>I want to read file paths irrespective of whether they are HDFS or local. Currently, I pass the local paths with the prefix file:// and HDFS paths with the prefix hdfs:// and write some code as the following</p>
  
  <pre><code>Configuration configuration = new Configuration();
  FileSystem fileSystem = null;
  if (filePath.startsWith("hdfs://")) {
    fileSystem = FileSystem.get(configuration);
  } else if (filePath.startsWith("file://")) {
    fileSystem = FileSystem.getLocal(configuration).getRawFileSystem();
  }
  </code></pre>
  
  <p>From here I use the API's of the FileSystem to read the file.</p>
  
  <p>Can you please let me know if there is any other better way than this?</p>