zbb20171214 java 获取classpath路径

  //获取classpath路径

  String path2 = Thread.currentThread().getContextClassLoader().getResource("").getPath();
        System.out.println("path2 = " + path2);
        System.out.println(System.currentTimeMillis());

//一下是获取文件路径路径

// 创建文件夹
        File file = new File("./src/main/resources/static/uploadFile/");
        System.out.println(file.getAbsolutePath());
        if (!file.exists()) {
            file.mkdir();
        }


        System.out.println(System.getProperty("user.dir"));
        File directory = new File("");// 设定为当前文件夹
        try {
            System.out.println(directory.getCanonicalPath());// 获取标准的路径
            System.out.println(directory.getAbsolutePath());// 获取绝对路径
        } catch (Exception e) {
        }

原文地址:https://www.cnblogs.com/super-admin/p/8037787.html