我写了一个方法,将指定Path
的所有文件复制到本地目录。
如何从列出的文件中获取相对路径名?
FileSystem fs = ...;
// remote directory whose files are copied from
org.apache.hadoop.fs.Path path = new Path("/path/to/the/directory");
// local directory into which files are copied.
java.nio.file.Path directory = ...;
for (LocatedFileStatus status : fs.listFiles(path, true)) {
// status: HdfsNamedFileStatus{path=hdfs://.../path/to/the/directory/.../...; ...}
// status.getPath(): hdfs://.../path/to/the/directory/.../...
// How can I get a relative path name for each status
// against the source path
// so that I can createDirectories on the target directory?
// I need the .../... part from hdfs://.../path/to/the/directory/.../...
// so that I can call Files.createDirectories(directory.resolve(.../...))
}
1条答案
按热度按时间uidvcgyl1#
我认为您可以用途:
获取目录的内容。