今天调试hadoop读取文件系统的时候遇到了一个java.io.EOFException异常

原始代码

String path="hdfs://master:9000/user/hadoop-0.20.2/tmp/7-0-initial-docid";
			FileSystem fs = FileSystem.get(URI.create(path), context.getConfiguration());
			FSDataInputStream in = null;
			in = fs.open(new Path(path));
			//InputStreamReader istr = new InputStreamReader(in);
			//BufferedReader br = new BufferedReader(istr);
			long id;
			while (id=in.readLong()>0L){
		            docID.add(id);
			}


后来将其中的while循环改为如下即可

                      while (in.available()>0){
				     id=in.readLong();
					 docID.add(id);
			}

因为读取的时候需要判断文件结尾

Logo

腾讯云面向开发者汇聚海量精品云计算使用和开发经验,营造开放的云计算技术生态圈。

更多推荐