20,808
社区成员
发帖
与我相关
我的任务
分享
package hadoop.hdfs;
import org.apache.hadoop.conf.Configuration;
import org.apache.hadoop.fs.FileSystem;
import org.apache.hadoop.fs.Path;
import org.junit.After;
import org.junit.Before;
import org.junit.Test;
import java.net.URI;
/**
* Hadoop HTFS java API 操作
**/
public class HDFSApp {
public static final String HDFS_PATH = "hdfs://localhost:9000";//试过将虚拟机主机名localhost改为ip192.168.100.128
FileSystem fileSystem = null;
Configuration configuration = null;
/**
* 创建HDFS目录
**/
@Test
public void mkdir() throws Exception {
fileSystem.mkdirs(new Path("HDFSApp/test"));
}
@Before
public void setUp() throws Exception {
System.out.println("HDFSApp.setup");
configuration = new Configuration();
fileSystem = FileSystem.get(new URI(HDFS_PATH), configuration, "root"); //这里将root改为虚拟机上的另一用户hadoop也不行
}
@After
public void tearDown() throws Exception {
configuration = null;
fileSystem = null;
System.out.println("HDFSApp.teardown");
}
}