About Hadoop HDFs for read-write file operations

Source: Internet
Author: User

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

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.