Configuration conf = new Configuration();
try {
conf.set("fs.defaultFS",<<namenode>>); //something like hdfs://server:9000 or copy from core-site.xml
FileSystem fileSystem= FileSystem.get(conf);
System.out.println("Uploading please wait...");
fileSystem.copyFromLocalFile(false, new Path(args[0]), new Path(args[1].trim()));//args[0]=C://file or dir args[1]=/imported
5条答案
按热度按时间9nvpjoqh1#
查看hadoop文档:copyfromlocal
请记住,创建apacheflume并不是为了复制
some
文件夹。u3r8eeie2#
在hadoop 2.0(yarn)中,您可以执行以下操作将本地文件传输到hdfs:
其中hdfs是位于bin目录中的命令。
wwodge7n3#
java代码很容易做到这一点。你不需要任何工具。检查下面的代码:
准备好jar并在任何操作系统上运行。请记住,您不需要在机器上运行hadoop,您将在那里运行这些代码。如果您需要任何帮助,请添加注解。
别忘了在运行代码的地方添加dnsresolver行。打开
/drivers/etc/hosts
(适用于windows)cx6n0qe34#
你也可以使用
hadoop fs -put <localsrcpath> <hdfspath>
这是另一种选择copyFromLocal
jhiyze9q5#
首先,您需要使用将文档从windows机器加载到linux机器
filezilla
或其他工具。然后你需要使用:
以下命令也将起作用。