zoukankan      html  css  js  c++  java
  • Wrong FS: hdfs://centos1:9000/user/hadoop/input, expected: file:///

    java读取hdfs时报错:

    Wrong FS: hdfs://centos1:9000/user/hadoop/input, expected: file:///

    首先确认 是用 FileSystem.get(conf) 而不是 FileSystem.getLocal(conf) 初始化的 FileSystem 对象.

    如果还有问题: 把集群里的 core-site.xml mapped-site.xml hdfs-site.xml slaves 等文件拷贝到eclipse 配置的 Hadoop 目录里.

    //hdfs://centos1:9000//user/hadoop/input hdfs://centos1:9000//user/hadoop/output
    	public static void main(String[] args) throws Exception {
    		Configuration conf = new Configuration();
    		Path inputPath = new Path("hdfs://centos1:9000/user/hadoop/input/");
    		//FileSystem file = FileSystem.getLocal(conf);
    		FileSystem file = FileSystem.get(conf);
    		FileStatus[] fileStatus = file.listStatus(inputPath);
    		byte[] temp = new byte[1024];
    		if(fileStatus!=null && fileStatus.length>0){
    			for (FileStatus status : fileStatus) {
    				System.out.println(status.getPath().getName() + "--"+ status.getLen()/1024/1024.0);
    				FSDataInputStream in = file.open(status.getPath());
    				int i = 0;
    				while((in.read(temp))!=-1){
    					System.out.println(new String(temp, 0, i));
    				}
    				in.close();
    			}
    		}
    		file.close();
    		System.out.println("end.");
    	}
    

      

  • 相关阅读:
    团购倒计时
    折半查找
    比较函数
    行为驱动开发: Cucumber的目录结构和执行过程 (转载)
    ruby 方法查找 and执行方法
    Rubyinstance_variable_get(@xx)
    Ruby 模块
    散列
    ruby webdriver 启动firefox driver时,加载firebug的扩展
    git使用简介
  • 原文地址:https://www.cnblogs.com/BennyTian/p/3005773.html
Copyright © 2011-2022 走看看