Hadoop Learning Record (ii) HDFS Java API

Source: Internet
Author: User

Fsdateinputstream Object

The open () method in the FileSystem object returns the Fsdateinputstream object, and the class inherits the Java.io.DateInoutStream interface. support for random access

Seekable interface

Supports locating the specified location in the file and provides a query method that queries the current position relative to the file start position offset.

public interface seekable{    //seek () can be moved to any absolute position in the file    void Seek (long POS);    Long GetPos ();    Boolean  Seektonewsource (long Targetpos);}

It is important to note that the Seek () method is a relatively expensive operation that requires careful use. To access files, use streaming data such as MapReduce, rather than a lot of seek ()!

Write Data

FileSystem How to create a new folder

    • Public Fsdaateoutputstream Create (path f); The method specifies a path object that is automatically created if it does not exist Sometimes we want to report a failure when the folder does not exist, instead of creating the write, then we need to call exists () to determine.
    • Another method is append (), which allows data to be appended at the end of an existing file
    • The progress () method is used to pass the callback interface, which notifies the application that the data is being written to Datenode.
1String localsrc = args[0];2String DST = args[1];3 //get file Read stream4InputStream in =NewInputStream (NewFileInputStream (LOCALSRC));5 6Configuration conf =NewConfiguration ();7FileSystem fs =Filesystem.get (Uri.create (DST), conf);8OutputStream out = Fs,create (NewPath (DST),Newprogressable () {9      Public voidProgress () {TenSyso. ("running!") One     } A});

Fsdataoutputstream Object

The object is not allowed to be positioned when writing to a file, only sequentially, appended to the end of the file.

Filestatus Object

Use the Filesystem.getfilestatus () method to return information and status for a file. Includes file length, block size, copy, modification time, owner and permissions.

Hadoop Learning Record (ii) HDFS Java API

Related Article

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.