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

      

  • 相关阅读:
    nignx的master进程和worker进程的作用
    JVM运行机制
    ElasticSearch介绍与安装
    Maven打可执行包的pom.xml配置
    pg按日,周,月进行数据统计
    数据库中重复数据查询和删除
    聚类算法的评估应面向具体问题
    将博客搬至CSDN
    Mutual Information
    层次化聚类
  • 原文地址:https://www.cnblogs.com/BennyTian/p/3005773.html
Copyright © 2011-2022 走看看