ITPub博客

首页 > 大数据 > 数据分析 > hadoop 文件夹文件的创建与删除

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

原创 数据分析 作者:hgs19921112 时间:2018-10-22 19:41:01 0 删除 编辑
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博客 ” ,链接:https://blog.itpub.net/31506529/viewspace-2217164/ ,如需转载,请注明出处,否则将追究法律责任。

请登录后发表评论 登录
全部评论

注册时间:2017-11-22

  • 博文量
    106
  • 访问量
    186402