路径获取

String userhome, workspace, project;

    userhome = System.getProperty("user.home", "~").replace(File.separatorChar, '/');
    File pwd = null;
    try {
        pwd = new File(new File(".").getCanonicalPath());
    } catch (IOException e) {
        e.printStackTrace();
    }
    workspace = pwd.getParentFile().getAbsolutePath().replace(File.separatorChar, '/');//new File("..").getCanonicalPath()...
    project = pwd.getName();

    System.out.println("pwd = " + pwd + "userhome=" + userhome + "workspace=" + workspace + "project=" + project);

你可能感兴趣的:(JavaSE)