Problem: Java could not link error display rejected link just started thinking that Hadoop is not well-equipped (or its own jar package did not import well), began to go away and lead to wasted time
The reason: Hadoop doesn't open up ...
A read-write code is as follows
Package Com;import Java.io.ioexception;import org.apache.hadoop.conf.configuration;import Org.apache.hadoop.fs.fsdatainputstream;import Org.apache.hadoop.fs.fsdataoutputstream;import Org.apache.hadoop.fs.filesystem;import Org.apache.hadoop.fs.Path; Public classNanshou { Public Static voidMain (string[] args) throws IOException {//HDFs ConnectionConfiguration conf=NewConfiguration (); FileSystem FS= FileSystem.Get(conf); //Requirements 1Fs.mkdirs (NewPath ("/usr/local/hadoop/l"));//Create a folderPath InFile1 =NewPath ("/usr/local/hadoop/l/hdfstest1.txt");//Create text Hdfstest1.txtFsdataoutputstream outputstream1=fs.create (INFILE1); Outputstream1.writeutf ("letter 1605-1 20163678 hu HDFs Classroom Test");//inputOutputstream1.flush (); Outputstream1.close (); //Requirements 2Path infile2=NewPath ("/usr/local/hadoop/l/hdfstest2.txt");//Create text Hdfstest2.txtFsdataoutputstream outputstream2=fs.create (InFile2); Fsdatainputstream inputStream1=fs.open (INFILE1);//Open Hdfstest1.txtOutputstream2.writeutf (Inputstream1.readutf ());//read Hdfstest1.txt content and write to Hdfstest2.txtOutputstream2.flush (); Outputstream2.close (); Inputstream1.close (); //Requirements 3Fsdatainputstream Inputstream2=fs.open (InFile2);//Open Hdfstest2.txtSystem. out. println (Inputstream2.readutf ());//Output//Open Hdfstest2.txt ContentInputstream2.close (); } }
About Hadoop HDFs for read-write file operations