本地读取HDFS文件

static public ArrayList getContentFromHDFS(String filePath)
	{
		BufferedReader in = null;
		ArrayList lstResult = new ArrayList();
		try {
			Configuration conf = new Configuration();
			FileSystem fs = FileSystem.get(conf);
			FSDataInputStream fin = fs.open(new Path(filePath));
			String line;

			in = new BufferedReader(new InputStreamReader(fin, "UTF-8"));
			while ((line = in.readLine()) != null) {
				lstResult.add(line);
			}
			if (in != null)
				in.close();
		} catch (IOException e) {
			e.printStackTrace();
		}
		return lstResult;
	}

你可能感兴趣的:(Java)