我希望读取文件路径时无论是HDFS还是本地路径都能够兼容。目前,我将本地路径加上前缀file://,将HDFS路径加上前缀hdfs://并编写以下代码:
Configuration configuration = new Configuration();
FileSystem fileSystem = null;
if (filePath.startsWith("hdfs://")) {
fileSystem = FileSystem.get(configuration);
} else if (filePath.startsWith("file://")) {
fileSystem = FileSystem.getLocal(configuration).getRawFileSystem();
}
从这里开始,我使用FileSystem的API来读取文件。
你能否告诉我是否有比这更好的方法?