Use the filesystem JAVA API to read, write, delete, HDFS, and so on __java

Source: Internet
Author: User
Tags parent directory file permissions hadoop fs
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.

01 Package hdfstest;
02
03 Import java.io.IOException;
04
05 Import org.apache.hadoop.conf.Configuration;
06 Import Org.apache.hadoop.fs.FSDataOutputStream;

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.