我正在考虑如何将 Hadoop 的输出写入 txt 文件,而不是写入 HDFS。例如,我把下面的代码:
// Create the job specification object
Job job1 = new Job();
job1.setJarByClass(Main.class);
job1.setJobName("Day Measurment");
// Setup input and output paths
FileInputFormat.addInputPath(job1, new Path(args[0]));
FileOutputFormat.setOutputPath(job1, new Path(args[1]));
// Set the Mapper and Reducer classes
job1.setMapperClass(DayMapper.class);
job1.setReducerClass(LogReducer.class);
// Specify the type of output keys and values
job1.setOutputKeyClass(Text.class);
job1.setOutputValueClass(LongWritable.class);
// Wait for the job to finish before terminating
job1.waitForCompletion(true);
PrintWriter pw = new PrintWriter("hadoop.csv");
pw.println("abc");
pw.close();
在我测试我的程序后,Hadoop 工作正常,但我只得到 hadoop.csv,里面没有内容。它是一个空文件,里面没有“abc”。
谁能告诉我为什么?或者告诉我如何将输出打印到常规文件(.csv 或 .log)中,而不是打印到 HDFS 中?