Hadoop文件系统删除源文件

Hadoop文件系统删除源文件,hadoop,hdfs,Hadoop,Hdfs,我使用以下方式将文件从本地PC上载到hdfs: FileSystem fs = FileSystem.get(conf); boolean deleteSrc = true; String destFile = "/user/admin/my.csv"; fs.copyFromLocalFile(deleteSrc,new Path(inputFile), new Path(destFile)); 这将导致文件从loca存储中删除。因此,复制实际上是一种“移动”。 如何上载loca文件的副本?

我使用以下方式将文件从本地PC上载到hdfs:

FileSystem fs = FileSystem.get(conf);
boolean deleteSrc = true;
String destFile = "/user/admin/my.csv";
fs.copyFromLocalFile(deleteSrc,new Path(inputFile), new Path(destFile));
这将导致文件从loca存储中删除。因此,复制实际上是一种“移动”。

如何上载loca文件的副本?

请注意,您正在将
copyFromLocalFile
调用的第一个参数设置为true,这会导致本地文件被删除。如果要保留本地文件,请将
deleteSrc
设置为
false

以下是
copyFromLocalFile
方法的详细信息

src文件位于本地磁盘上。以给定的dst名称将其添加到文件系统中。delSrc指示是否应删除源

参数:

delSrc - whether to delete the src
overwrite - whether to overwrite an existing file
srcs - array of paths which are source
dst - path
IOException - IO failure
抛出:

delSrc - whether to delete the src
overwrite - whether to overwrite an existing file
srcs - array of paths which are source
dst - path
IOException - IO failure

您也可以参考。

如果您不想从本地删除,我认为
deleteSrc
应该设置为
false