首页 > 代码库 > 使用hadoop的类操作HDFS

使用hadoop的类操作HDFS

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);	}

  

 

使用hadoop的类操作HDFS