Reading HDFS and local files in Java

前端 未结 3 1660
难免孤独
难免孤独 2020-12-08 10:45

I want to read file paths irrespective of whether they are HDFS or local. Currently, I pass the local paths with the prefix file:// and HDFS paths with the prefix hdfs:// an

3条回答
  •  借酒劲吻你
    2020-12-08 11:36

    You can get the FileSystem by the following way:

    Configuration conf = new Configuration();
    Path path = new Path(stringPath);
    FileSystem fs = FileSystem.get(path.toUri(), conf);
    

    You do not need to judge if the path starts with hdfs:// or file://. This API will do the work.

提交回复
热议问题