美文网首页
Hadoop HDFS文件操作API

Hadoop HDFS文件操作API

作者: 不学无术 | 来源:发表于2016-10-09 10:11 被阅读0次

使用JAVA操作HDFS:

public void testApp() throws Exception {
    
    String uri = "hdfs://192.168.0.88:9000/";  
    Configuration config = new Configuration();  
    FileSystem fs = FileSystem.get(URI.create(uri), config);  

    // 列出hdfs上/test/input/目录下的所有文件和目录  
    FileStatus[] statuses = fs.listStatus(new Path("/test/input"));  
    for (FileStatus status : statuses) {  
        System.out.println(status);  
    }  

    // 在hdfs的/test/input/目录下创建一个文件,并写入一行文本  
    FSDataOutputStream os = fs.create(new Path("/test/input/test.log"));  
    os.write("Hello World!".getBytes());  
    os.flush(); 
    os.close(); 

    // 显示在hdfs的/test/input/下指定文件的内容  
    InputStream is = fs.open(new Path("/test/input/test.log"));  
    IOUtils.copyBytes(is, System.out, 1024, true);  
    
    assertTrue(true);
}

使用Shell操作HDFS:
<code>
Usage: hadoop fs [generic options]
[-appendToFile <localsrc> ... <dst>]
[-cat [-ignoreCrc] <src> ...]
[-checksum <src> ...]
[-chgrp [-R] GROUP PATH...]
[-chmod [-R] <MODE[,MODE]... | OCTALMODE> PATH...]
[-chown [-R] [OWNER][:[GROUP]] PATH...]
[-copyFromLocal [-f] [-p] <localsrc> ... <dst>]
[-copyToLocal [-p] [-ignoreCrc] [-crc] <src> ... <localdst>]
[-count [-q] <path> ...]
[-cp [-f] [-p] <src> ... <dst>]
[-createSnapshot <snapshotDir> [<snapshotName>]]
[-deleteSnapshot <snapshotDir> <snapshotName>]
[-df [-h] [<path> ...]]
[-du [-s] [-h] <path> ...]
[-expunge]
[-get [-p] [-ignoreCrc] [-crc] <src> ... <localdst>]
[-getmerge [-nl] <src> <localdst>]
[-help [cmd ...]]
[-ls [-d] [-h] [-R] [<path> ...]]
[-mkdir [-p] <path> ...]
[-moveFromLocal <localsrc> ... <dst>]
[-moveToLocal <src> <localdst>]
[-mv <src> ... <dst>]
[-put [-f] [-p] <localsrc> ... <dst>]
[-renameSnapshot <snapshotDir> <oldName> <newName>]
[-rm [-f] [-r|-R] [-skipTrash] <src> ...]
[-rmdir [--ignore-fail-on-non-empty] <dir> ...]
[-setrep [-R] [-w] <rep> <path> ...]
[-stat [format] <path> ...]
[-tail [-f] <file>]
[-test -[defsz] <path>]
[-text [-ignoreCrc] <src> ...]
[-touchz <path> ...]
[-usage [cmd ...]]

</code>

相关文章

网友评论

      本文标题:Hadoop HDFS文件操作API

      本文链接:https://www.haomeiwen.com/subject/irhhhttx.html