package com.example.demo;
import java.io.FileInputStream;
import java.io.FileOutputStream;
import org.apache.hadoop.conf.Configuration;
import org.apache.hadoop.fs.FSDataInputStream;
import org.apache.hadoop.fs.FSDataOutputStream;
import org.apache.hadoop.fs.FileSystem;
import org.apache.hadoop.fs.Path;
import org.apache.hadoop.io.IOUtils;
import org.springframework.stereotype.Component;
@Component
public class HDFSDemo {
public void copyFileFromLocal() {
//1 创建连接
Configuration conf = new Configuration();
//2 连接端口
conf.set("fs.defaultFS", "hdfs://192.168.78.166:9000");
//3 获取连接对象
try {
FileSystem fs = FileSystem.get(conf);
//4 本地文件上传到 hdfs
fs.copyFromLocalFile(new Path("C://test.txt"), new Path("/test"));
fs.close();
} catch (Exception e) {
e.printStackTrace();
}
}
}
写一个简单的文件上传&#x