HDFS文件下載

    /**
     * 文件下載
     * @throws IOException
     * @throws InterruptedException
     * @throws URISyntaxException
     */
    @Test
    public void testCopyToLocalFile() throws IOException, InterruptedException, URISyntaxException{

        // 1 獲取文件系統
        Configuration configuration = new Configuration();
        FileSystem fs = FileSystem.get(new URI("hdfs://192.168.2.210:9000"), configuration, "atguigu");

        // 2 執行下載操作
        // boolean delSrc 指是否將原文件刪除
        // Path src 指要下載的文件路徑
        // Path dst 指將文件下載到的路徑
        // boolean useRawLocalFileSystem 是否開啓文件校驗
        fs.copyToLocalFile(false, new Path("/keymap-shkstart.jar"), new Path("e:/keymap-shkstart.jar"), true);

        // 3 關閉資源
        fs.close();
    }

 

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