import java.io.FileInputStream;
import java.io.IOException;
import java.net.URI;
import org.apache.commons.io.IOUtils;
import org.apache.hadoop.conf.Configuration;
import org.apache.hadoop.fs.FSDataOutputStream;
import org.apache.hadoop.fs.FileSystem;
import org.apache.hadoop.fs.Path;
import org.junit.Before;
import org.junit.Test;
public class HdfsUtil {
FileSystem fs=null;
@Before
public void init() throws Exception{
Configuration conf=new Configuration();
conf.set("fs.defaultFS", "hdfs://weekend110:9000/");
fs=FileSystem.get(new URI("hdfs://weekend110:9000/"),conf,"hadoop");
}
/**
* 下载文件
* @throws Exception
* @throws IllegalArgumentException
*/
@Test
public void download() throws Exception{
fs.copyToLocalFile(new Path("hdfs://weekend110:9000/aa/qingshu.txt"),new Path("E:/qingshu2.txt"));
}
}
经过一番搜索 已解决
加上两个参数 就能正常下载
fs.copyToLocalFile(false,new Path("hdfs://weekend110:9000/aa/qingshu.txt"),new Path("E:/qingshu2.txt"),true);