hdfs下载copyToLocalFile报NullPointerException解决方法

时间:2023-01-31 22:39:55

fs.copyToLocalFile(new Path("/**.***"), new Path("e:/**.***"));

报NullPointerException,可能是因为windows下系统环境变量引起,试验出两种解决方法:

InputStream in = fs.open(new Path("/**.***"));
FileOutputStream out = new FileOutputStream(new File("e:/**.***"));
IOUtils.copyBytes(in, out, 2048, true);

使用open方法以及hadoop提供的copyBytes

方法二:

fs.copyToLocalFile(false, new Path("/**.***"), new Path("e:/**.***"), true);

使用带4个参数的copyToLocalFile方法(

void org.apache.hadoop.fs.FileSystem.copyToLocalFile(boolean delSrc, Path src,Path dst,boolean useRawLocalFileSystem) throws IOException
),最后一个参数表示不用原始的本地文件系统,改用java的io流