码迷,mamicode.com
首页 > 其他好文 > 详细

使用hadoop的类操作HDFS

时间:2015-01-19 00:12:26      阅读:263      评论:0      收藏:0      [点我收藏+]

标签:

1. 创建文件夹

    private static final String PATH = "hdfs://hadoop:9000/";
    private static final String DIR = "/d2";
    
    public static void main(String[] args) throws Exception 
    {
        FileSystem fileSystem = FileSystem.get(new URI(PATH), new Configuration());
        fileSystem.mkdirs(new Path(DIR));
    }

 2.上传文件

        private static final String PATH = "hdfs://hadoop:9000/";
	private static final String FILE = "/d2/hello";
	
	public static void main(String[] args) throws Exception 
	{
		FileSystem fileSystem = FileSystem.get(new URI(PATH), new Configuration());
		FSDataOutputStream out = fileSystem.create(new Path(FILE));
		FileInputStream in = new FileInputStream("D:/readme.txt");
		IOUtils.copyBytes(in, out, 1024, true);
	}

  

 

使用hadoop的类操作HDFS

标签:

原文地址:http://www.cnblogs.com/lzxl/p/4232607.html

(0)
(0)
   
举报
评论 一句话评论(0
登录后才能评论!
© 2014 mamicode.com 版权所有  联系我们:gaon5@hotmail.com
迷上了代码!