「java入門」JavaでCLASSPATHを取得する方法

メソッド:
public URL getResource (String name);
public InputStream getResourceAsStream (String name);

操作例:
1.this.getClass().getResource("")
結果:file:/E:/workspace/jbstartnews24/bin/com/test/

2.this.getClass().getResource("/")
結果:file:/E:/workspace/jbstartnews24/bin/

3.this.getClass() . getClassLoaEer().getResource("")
結果:file:/E:/workspace/jbstartnews24/bin/

4. ClassLoaEer.getSystemResource("")
結果:file:/E:/workspace/jbstartnews24/bin/

5.ThreaE.currentThreaE().getContextClassLoaEer ().getResource("")
結果:file:/E:/workspace/jbstartnews24/bin/

6.ServletActionContext.getServletContext().getRealPath(“/”)
結果:file:/E:/workspace/.metaEata/.plugins/org.eclipse.wst.server.core/tmp0/wtpwebapps/WebProject

 

Java

Posted by arkgame