怎么得到java类当前路径

怎么得到java类的当前路径而不是编印后的对应的.class文件路径

我写了一个类 它的路径是
E:\workspace\WorkFlow\WorkFlow\src\com\njusoft\syschroFlow\test(这个是我要想得到的路径)

类如下

public class FilePath {
public void Print(){
String a=this.getClass().getClassLoader().getResource(".").getPath();
String b=this.getClass().getResource("").getPath();
String c=this.getClass().getResource(" ").getPath();
String d=this.getClass().getResource("/").getPath();
          String e=System.getProperty("user.dir");
System.out.println(a);
System.out.println(b);
System.out.println(c);
System.out.println(d);
                  System.out.println(e);
System.out.println("*********************");

}


public static void main(String[] args) {

   FilePath  f=new FilePath();
   f.Print();

}
}

这样运行结果如下:
/E:/workspace/WorkFlow/WorkFlow/WebRoot/WEB-INF/classes/
/E:/workspace/WorkFlow/WorkFlow/WebRoot/WEB-INF/classes/com/njusoft/syschroFlow/test/
/E:/workspace/WorkFlow/WorkFlow/WebRoot/WEB-INF/classes/com/njusoft/syschroFlow/test/%20
/E:/workspace/WorkFlow/WorkFlow/WebRoot/WEB-INF/classes/
E:\workspace\WorkFlow\WorkFlow

*********************

我有如下几点疑惑希望各位能指点一下:
1为什么路径前还有一个/(E盘前),还有那个斜杠怎么是反的呢?
2为什么都是FilePath编译的对应的.class路径呢?
3getResource("."),getResource(""),getResource(" "),getResource   ("/")里的参数是什么意思?
 
注意 1 String a 那行 我改为 String a=this.getClass().getClassLoader().getResource("/").getPath();就报错
错误:Exception in thread "main" java.lang.NullPointerException
at com.njusoft.syschroFlow.test.FilePath.Print(FilePath.java:5)
at com.njusoft.syschroFlow.test.FilePath.main(FilePath.java:21)
2 还有就是getResource(""),比getResource(" ")多一个 %20

我第一次写博客发表文章 请各位大侠帮一下忙,非常感谢。

第一次在这里写文章,才两个星期不到就扣了三次分,封了两次了唉! 早晨来看看见帖子有人回了 就过去回复一下发现自己又被封了         。写好的话不能贴到给我回复的人博客。
先写在我自己这里好了。
回复 抛出异常的爱
看到你的回帖我很(java相对路径)高兴 ,因为看见的博客在javaeye上有排名。心想牛人啊。牛人平易近人。可是我不懂 怎么把eclipse编译路径指向 src 能告诉具体告诉我一下吗?呵呵 太菜了。
  

你可能感兴趣的:(java,eclipse,Web,workflow,ide)