HDFS读写操作
public class HdfsOp {
public static void main(String[] args) throws Exception {
hdfsReadFile("hdfs://192.168.153.133:9000/",
"hdfs://192.168.153.133:9000/spark/sparktmp.txt" );
hdfsWriteFile("out/ww.txt","hdfs://chen133:9000/",
"hdfs://192.168.153.133:9000/spark/world.txt");
}
public static void hdfsReadFile(
String hdfsUrl,String hdfsFile) throws Exception {
Configuration cfg=new Configuration();
//"fs.defaultFS"获取配置文件中设置的hdfs端口
cfg.set("fs.defaultFS",hdfsUrl);
//获取文件
FileSystem fs=FileSystem.get(cfg);
if (!fs.exists(new Path(hdfsFile))){
throw new Excepti