HDFS文件上傳


    /**
     * 將本地文件上傳到hdfs
     * @throws IOException
     * @throws InterruptedException
     * @throws URISyntaxException
     */
    @Test
    public void testCopyFromLocalFile() throws IOException, InterruptedException, URISyntaxException {

        // 1 獲取文件系統
        Configuration configuration = new Configuration();
        configuration.set("dfs.replication", "2");
        FileSystem fs = FileSystem.get(new URI("hdfs://192.168.2.210:9000"), configuration, "atguigu");
        // 2 上傳文件
        fs.copyFromLocalFile(new Path("e:/keymap-shkstart.jar"), new Path("/keymap-shkstart.jar"));
        // 3 關閉資源
        fs.close();
        System.out.println("over");
    }

 

發表評論
所有評論
還沒有人評論,想成為第一個評論的人麼? 請在上方評論欄輸入並且點擊發布.
相關文章