在JavaHDFS中读取文件
我在集群上运行该程序时遇到了问题,决定从函数map和reduce中的hdfs文件中读取。如何逐行读取hdfs文件并刻录以读取ArrayList中的行?只需一段代码片段进行演示:在JavaHDFS中读取文件,java,linux,hadoop,solaris,hdfs,Java,Linux,Hadoop,Solaris,Hdfs,我在集群上运行该程序时遇到了问题,决定从函数map和reduce中的hdfs文件中读取。如何逐行读取hdfs文件并刻录以读取ArrayList中的行?只需一段代码片段进行演示: Path path = new Path(filePath); FileSystem fs = path.getFileSystem(context.getConfiguration()); // context of mapper or reducer FSDataInputStream fdsis = fs.open
Path path = new Path(filePath);
FileSystem fs = path.getFileSystem(context.getConfiguration()); // context of mapper or reducer
FSDataInputStream fdsis = fs.open(path);
BufferedReader br = new BufferedReader(new InputStreamReader(fdsis));
String line = "";
ArrayList<String> lines = new ArrayList<String>();
while ((line = br.readLine()) != null) {
lines.add(line);
}
br.close();
Path Path=新路径(filePath);
FileSystem fs=path.getFileSystem(context.getConfiguration());//映射器或还原器的上下文
FSDataInputStream fdsis=fs.open(路径);
BufferedReader br=新的BufferedReader(新的InputStreamReader(fdsis));
字符串行=”;
ArrayList行=新的ArrayList();
而((line=br.readLine())!=null){
行。添加(行);
}
br.close();
只需一段代码片段进行演示:
Path path = new Path(filePath);
FileSystem fs = path.getFileSystem(context.getConfiguration()); // context of mapper or reducer
FSDataInputStream fdsis = fs.open(path);
BufferedReader br = new BufferedReader(new InputStreamReader(fdsis));
String line = "";
ArrayList<String> lines = new ArrayList<String>();
while ((line = br.readLine()) != null) {
lines.add(line);
}
br.close();
Path Path=新路径(filePath);
FileSystem fs=path.getFileSystem(context.getConfiguration());//映射器或还原器的上下文
FSDataInputStream fdsis=fs.open(路径);
BufferedReader br=新的BufferedReader(新的InputStreamReader(fdsis));
字符串行=”;
ArrayList行=新的ArrayList();
而((line=br.readLine())!=null){
行。添加(行);
}
br.close();
使用TextInputFormat默认的InputSplit是一个FileInputSplit,将代表一整行。您到底遇到了什么问题?使用TextInputFormat,默认的InputSplit是一个FileInputSplit,将代表一整行。你到底有什么问题?