要将文件上传到HDFS,可以使用以下方法:
hadoop fs -put <local_file_path> <hdfs_directory_path>
hdfs dfs -put <local_file_path> <hdfs_directory_path>
import org.apache.hadoop.conf.Configuration;
import org.apache.hadoop.fs.FileSystem;
import org.apache.hadoop.fs.Path;
public class UploadFileToHDFS {
public static void main(String[] args) {
String localFilePath = "path/to/local/file";
String hdfsDirectoryPath = "hdfs://localhost:9000/user/hadoop/";
Configuration conf = new Configuration();
try {
FileSystem fs = FileSystem.get(conf);
fs.copyFromLocalFile(new Path(localFilePath), new Path(hdfsDirectoryPath));
System.out.println("File uploaded to HDFS successfully");
} catch (Exception e) {
e.printStackTrace();
}
}
}
以上是常用的方法,可以根据具体的需求选择适合自己的方法上传文件到HDFS。
辰迅云「云服务器」,即开即用、新一代英特尔至强铂金CPU、三副本存储NVMe SSD云盘,价格低至29元/月。点击查看>>
推荐阅读: hadoop错误日志怎么查看