Java 写入hdfs程序代码
在这里直接上代码
Configurationconf = new Configuration();
conf.set("fs.hdfs.impl", org.apache.hadoop.hdfs.DistributedFileSystem.class.getName());
conf.set("fs.file.impl",org.apache.hadoop.fs.LocalFileSystem.class.getName());
conf.setBoolean("dfs.support.append",true);
hdfs = FileSystem.get(conf);
String hdfs ="hdfs://10.20.30.91:8020/kafka/a.log";
filePath = new Path(hdfs);
FSDataOutputStream outputStream = hdfs.create(filePath);
outputStream.write(“hello”)
outputStream.flush();
outputStream.close();
hdfs.close();
在这里我说一下这一段代码:
conf.set("fs.hdfs.impl", org.apache.hadoop.hdfs.DistributedFileSystem.class.getName());
conf.set("fs.file.impl",org.apache.hadoop.fs.LocalFileSystem.class.getName());
假如不配置上面这段话,在maven 打包或