Hadoop file System
Basic file System command operation, through Hadoop Fs-help can get all the commands of the detailed help file.
The Java abstract class Org.apache.hadoop.fs.FileSystem defines a file system interface for Hadoop. This class is an abstract class that can be used to filesystem instances through the following two static factory methods:
public static Filesystem.get (Configuration conf) throws IOException
public static filesystem.get (URI Uri, Configuration conf) throws IOException
Specific methods to achieve:
1. Public Boolean mkdirs (Path f) throws IOException
Create all directories at once (including the parent directory), and F is the complete directory path.
2. Public Fsoutputstream Create (Path f) throws IOException
Creates a file for the specified path object, returning an output stream for writing data
Create () has multiple overloaded versions, allowing us to specify whether to force overwriting of existing files, number of file backups, write file buffer size, file block size, and file permissions.
3. Public boolean copyfromlocal (path src, path DST) throws IOException
Copy local files to the file system
4. Public Boolean exists (Path f) throws IOException
Check whether a file or directory exists
5, public boolean delete (Path F, Boolean recursive)
Permanently deletes the specified file or directory, and if f is an empty directory or file, then the recursive value is ignored. When only recursive=true, a non-empty directory and its contents are deleted.
6. The Filestatus class encapsulates metadata for files and directories in the file system, including file length, block size, backup, modification time, owner, and permission information.
The Filestatus.getpath () allows you to view all files in a directory in the specified HDFS.
03 |
Import java.io.IOException; |
05 |
Import org.apache.hadoop.conf.Configuration; |
06 |
Import Org.apache.hadoop.fs.FSDataOutputStream; |