HA 下执行JAVA操作hdfs

1 拷贝HA中core.xml和hdfs.xml文件到工程src下

2 java代码,其中ns1是nameservice名称

public class HDFSHATest {
	public static void main(String[] args) throws Exception
	{	
		 Configuration conf = new Configuration() ;
		 FileSystem fs = FileSystem.get( new URI("hdfs://ns1"),conf,"hadoop") ;
		 fs.copyFromLocalFile( new Path("e://1.txt"), new Path("hdfs://ns1/"));
	}
}

猜你喜欢

转载自username2.iteye.com/blog/2271270