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.");
    	}
    

      

  • 相关阅读:
    浅析Json底层
    浅析servlet
    xml树结构
    JS中BOM和DOM之间的关系
    Test openLiveWriter
    JAVA静态代理动态代理详解
    java多态实现示例
    java类中的变量以及方法的执行顺序
    java值传递
    将javaweb项目部署到服务器中
  • 原文地址:https://www.cnblogs.com/BennyTian/p/3005773.html
Copyright © 2011-2022 走看看