hadoop 文件系统API操作

时间:2023-03-08 17:23:17

配置参数:-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"));
}