java - Reading data from HDFS - my program can't find the path -
I am trying to read the contents of the file from HDFS. My code is below -
Package General; Import java.io.buffferedReader; Import java.io.IOException; Import java.io.InputStreamReader; Import org.apache.hadoop.conf.configuration; Import org.apache.hadoop.fs.FileSystem; Import org.apache.hadoop.fs.Path; Public Class ReadFromHDFS {Public Static Zero Main (string [] args throws exceptions {if (args.length & lt; 1) {System.out.println ("Usage: ReadFromHDFS & lt; hdfs-file-path-to- Read-from & gt; "); System.out.println ("Example: ReadFromHDFS 'hdfs: / localhost: 9000 / myFirstSelfWriteFile'"); System.exit (-1); } {Try Path Path = New Path (Argos [0]); FileSystem fileSystem = FileSystem.get (new configuration ()); Buffer Reader buffedreader = new buffed reader (new inputstreamreader (file system.open (path)); string line = buffedreader .readline (); while (line! = Null) {System.out.println (line); line = buffer.readline ();}} Grip (IOException e) {e.printStackTrace ();}}}
However, I did not know how to program this path to my HDFS directory I tried -
java-cp Gen.ReadFromHDFS & lt; path & gt;
where With the path I tried to refer straight to the directory (what do I see when I do THeP FS-L), directory inside the file, adding hdfs: / localhost, hdfs: / and none do work from them Can anyone help me how to fix the path of my folder to HDFS? For example, when I give the path directly (without any prefix), it says that the file does not exist. / P>
Npadit: Now none of the solutions is also not working for me I get are always exceptions -
java.io.FileNotFoundExceptoin: file & lt; Filename & gt; Does not exist. Trying to find this file locally.
Comments
Post a Comment