利用Quartz任务调度框架定期将网站产生的日志数据文件通过hadoop的hdfs的api加入到集群的hdfs中
具体实现:
通过配置文件设置调度模式,通过调度框架的api调用hdfs的api实现定期往hdfs中添加文件
publicclass QuartzJob {
publicvoid work() {
readFile();
}
}
public void readFile() throws Exception{
Configuration configuration = new Configuration();
URI uri = new URI("hdfs://hadoop240:9000/");
FileSystem fs =FileSystem.get(uri, configuration);
FSDataOutputStream out = fs.create(new Path("/hdfs文件地址"));
FileInputStream in = new FileInputStream("/目标文件地址"); IOUtils.copyBytes(in, out, 1024, true);
}