hadoop 文件夹文件的创建与删除


package hadoop.test;
import java.io.IOException;
import java.net.URI;
import java.net.URISyntaxException;
import org.apache.hadoop.conf.Configuration;
import org.apache.hadoop.fs.FileSystem;
import org.apache.hadoop.fs.Path;
public class FileSystemTest {
	public static void main(String[] args) throws IOException, URISyntaxException {
		Configuration cfg = new Configuration();
		FileSystem fs = FileSystem.get(new URI("hdfs://data1:9000"),cfg);
		//fs.open(new Path(new URI("hdfs://data1:9000")));
		boolean flgs = fs.exists(new Path(new URI("/hgs")));
		if(flgs) {
			boolean flg = fs.isDirectory(new Path(new URI("/hgs")));
			System.out.println(flg);
			//这里会报错,添加 环境变量 HADOOP_USER_NAME=root
			//从本地copy一个文件到hdfs
			//fs.copyFromLocalFile(true,new Path("e:\\install.ini"), new Path("/hgs/tmp.txt"));
			
			//拷贝hdfs文件到本地
			//fs.copyToLocalFile(false,new Path("hdfs://data1:9000/hgs/tmp.txt"),new Path("e:\\tmp.txt"),true );
			
			//创建文件夹
			//boolean fl = fs.mkdirs(new Path("/hgs/hgstmp"));
			//System.out.println(fl);
			boolean f = fs.delete(new Path("/hgs/hgstmp"), true);
			System.out.println(f);
		}
		System.out.println(flgs);
		fs.close();
	}
}


来自 “ ITPUB博客 ” ,链接:http://blog.itpub.net/31506529/viewspace-2217164/,如需转载,请注明出处,否则将追究法律责任。

转载于:http://blog.itpub.net/31506529/viewspace-2217164/

你可能感兴趣的:(hadoop 文件夹文件的创建与删除)