public static void main(String[] args){
Test2 test = new Test2();
try {
test.showURL();
} catch (IOException e) {
// TODO Auto-generated catch block
e.printStackTrace();
}
}
public void showURL() throws IOException{
//获取类加载的跟路径
File f = new File(this.getClass().getResource("/").getPath());
System.out.println(f);
//获取项目路径
File directory = new File("");
String courseFile = directory.getCanonicalPath();//tomcat环境中运行,会获取会获取Tomcat安装目录的bin目录,不推荐使用
System.out.println(courseFile);
//
URL xmlpath = this.getClass().getClassLoader().getResource("");
System.out.println(xmlpath);
//获取当前工程路径
System.out.println(System.getProperty("user.dir"));
//当前目录的上一级目录
File ff = new File(System.getProperty("user.dir"));
System.out.println(ff.getParent());
//当前目录的下一级,我们可以利用流的读取 ,判断是不是文件夹,
//是文件夹得话,遍历里面的文件,里面若有自己的所需的文件夹,那就在拼一层
//E:\workspace\xiaofan+"\"+"文件名"
//可能也有最简单的方法找到他的下一级目录
//获取所有类的路径,包括jar的路径
System.out.println(System.getProperty("java.class.path"));
//System.getenv("JAVA_HOME").
System.out.println(System.console());
//获取环境变量的路径 D:\java\jdk1.8.0_40
// File curAllInOneProjectFile = new File(allInOneProjectPath);
// f.getParent();
/**
* public static Console console() {
if (cons == null) {
synchronized (System.class) {
cons = sun.misc.SharedSecrets.getJavaIOAccess().console();
}
}
return cons;
}
*/
//源码是加了锁,为了保证线程安全 是不是考虑用次
//
}