copyToLocalFile报错:(null) entry in command string: null chmod 0644

测试程序,从HDFS上下载文件到本地

package com.hadoop.hdfs;

import org.apache.hadoop.conf.Configuration;
import org.apache.hadoop.fs.FileSystem;
import org.apache.hadoop.fs.Path;

import java.io.IOException;
import java.net.URI;

public class GetFile {
    public static void main(String[] args) throws IOException {
        String hdfsPath="hdfs://192.168.55.128:9000/input/words.txt";
        String localPath="D:/copy_words.txt";
        Configuration cfg=new Configuration();
        FileSystem fs=FileSystem.get(URI.create(hdfsPath),cfg);
        Path hdfs_path=new Path(hdfsPath);
        Path local_path=new Path(localPath);
        fs.copyToLocalFile(hdfs_path,local_path);
        fs.close();
    }
}

 报错

解决办法

   fs.copyToLocalFile(false,hdfs_path,local_path,true);

 说明:
第一个false参数表示不删除源文件,第4个true参数表示使用本地原文件系统,因为这个Demo程序是在Windows系统下运行的。

因分析

查看官方API
http://hadoop.apache.org/docs/r2.7.6/api/

public void copyToLocalFile(boolean delSrc, Path src, Path dst, boolean useRawLocalFileSystem) throws IOException The src file is under FS, and the dst is on the local disk. Copy it from FS control to the local dst name. delSrc indicates if the src will be removed or not. useRawLocalFileSystem indicates whether to use RawLocalFileSystem as local file system or not. RawLocalFileSystem is non crc file system.So, It will not create any crc files at local. Parameters: delSrc - whether to delete the src src - path dst - path useRawLocalFileSystem - whether to use RawLocalFileSystem as local file system or not. Throws: IOException - - if any IO error

 

posted @ 2018-11-16 20:54  palyer  阅读(589)  评论(0编辑  收藏  举报