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