• 编程实现从hadoop上下载


    下载

    package hadoopTest;
    
    import java.io.File;
    import java.io.IOException;
    
    import org.apache.hadoop.conf.Configuration;
    import org.apache.hadoop.fs.FileSystem;
    import org.apache.hadoop.fs.Path;
    
    public class Merge {
        Path inputPath = new Path("/test4/text3");
        Path outputPath = new Path("e:/test1/text3");
        static int number = 0;
    
        public void doMerge() throws IOException {
            Configuration config = new Configuration();
            config.set("fs.default.name", "hdfs://192.168.20.128:9000");
            FileSystem fs = FileSystem.get(config);
            if (Merge.isExit(outputPath.toString())) {// 已经存在创建副本
                String tempPath = outputPath.toString();
                String[] paths = tempPath.split("\/");
                number++;
                String newPath = paths[paths.length - 1] + "副本" + number;
                for (; Merge.isExit("e:/test1/" + newPath);) {
                    number++;
                    newPath = paths[paths.length - 1] + "副本" + number;
                }
                Path newOutputPath = new Path("e:/test1/" + newPath);
                fs.copyToLocalFile(false, inputPath, newOutputPath);
            } else {// 不存在
                fs.copyToLocalFile(false, inputPath, outputPath);
            }
        }
    
        private static boolean isExit(String path) {// 判断文件是否存在
            File file = new File(path);
            boolean exit = file.exists();
            return exit;
        }
    }
    View Code
  • 相关阅读:
    Linux-exec族函数
    Linux-竟态初步引入
    Linux-waitpid介绍
    Java基础:Java运算符:算术运算符
    Java中的算术运算符
    JAVA冒泡排序
    引用 java的一些基本概念
    Tomcat服务器的下载安装跟基本配置
    Tomcat配置Web站点
    Tomcat+JSP经典配置实例
  • 原文地址:https://www.cnblogs.com/vhyc/p/6595620.html
Copyright © 2020-2023  润新知