配置参数:-DHADOOP_USER_NAME=hadoop
public class HdfsUtils { private static FileSystem fileSystem; @Before public void init() throws IOException { Configuration conf = new Configuration(); // fileSystem = FileSystem.get(conf); } @Test public void download() throws IOException { Configuration conf = new Configuration(); FileSystem fileSystem = FileSystem.get(conf); Path path = new Path("/test"); FSDataInputStream inStream = fileSystem.open(path); OutputStream outStream = new FileOutputStream("D:/test.txt"); IOUtils.copy(inStream, outStream); } @Test public void upload2() throws IllegalArgumentException, IOException { fileSystem.copyFromLocalFile(new Path("D:/test.txt"), new Path("/test.txt")); }