标签:
1. 创建文件夹
private static final String PATH = "hdfs://hadoop:9000/"; private static final String DIR = "/d2"; public static void main(String[] args) throws Exception { FileSystem fileSystem = FileSystem.get(new URI(PATH), new Configuration()); fileSystem.mkdirs(new Path(DIR)); }
2.上传文件
private static final String PATH = "hdfs://hadoop:9000/"; private static final String FILE = "/d2/hello"; public static void main(String[] args) throws Exception { FileSystem fileSystem = FileSystem.get(new URI(PATH), new Configuration()); FSDataOutputStream out = fileSystem.create(new Path(FILE)); FileInputStream in = new FileInputStream("D:/readme.txt"); IOUtils.copyBytes(in, out, 1024, true); }
标签:
原文地址:http://www.cnblogs.com/lzxl/p/4232607.html