| | |
Determinng currently running java file location?
Please support our Java advertiser: Programming Forums - DaniWeb Sister Site
Thread Solved |
•
•
Join Date: Oct 2009
Posts: 28
Reputation:
Solved Threads: 6
-1
#2 Oct 16th, 2009
You can use the ClassLoader to do that:
String className=this.getClass.getName();//Name of your class
ClassLoader cl=this.getClass.getClassLoader();
System.out.println(cl.getRessource(className + ".class"));
Or you can use it with the Thread Object:
cl= Thread.currentThread().getContextClassLoader();
System.out.println(cl.getRessource(className + ".class"));
String className=this.getClass.getName();//Name of your class
ClassLoader cl=this.getClass.getClassLoader();
System.out.println(cl.getRessource(className + ".class"));
Or you can use it with the Thread Object:
cl= Thread.currentThread().getContextClassLoader();
System.out.println(cl.getRessource(className + ".class"));
•
•
Join Date: Aug 2009
Posts: 17
Reputation:
Solved Threads: 0
0
#5 Oct 16th, 2009
I removed this. but still has an error.
It's saying:
1 error found:
File: C:\Documents and Settings\dolee\Desktop\test2.java [line: 3]
Error: C:\Documents and Settings\dolee\Desktop\test2.java:3: cannot find symbol
symbol : variable getClass
location: class test2
and I am testing in a test class file,
the code is like:
It's saying:
1 error found:
File: C:\Documents and Settings\dolee\Desktop\test2.java [line: 3]
Error: C:\Documents and Settings\dolee\Desktop\test2.java:3: cannot find symbol
symbol : variable getClass
location: class test2
and I am testing in a test class file,
the code is like:
Java Syntax (Toggle Plain Text)
public class test2 { public static void main(String args[]) { String className= getClass.getName(); ClassLoader cl=Thread.currentThread().getContextClassLoader(); System.out.println(cl.getResource(className + ".class")); } }
•
•
Join Date: Feb 2008
Posts: 100
Reputation:
Solved Threads: 5
0
#6 Oct 16th, 2009
Add "import java.io.File;" then use this code:
This will tell you the absolute path of the folder in which the java app is running (the "*.jar" file).
Hope I helped.
Java Syntax (Toggle Plain Text)
File f = new File("./"); System.out.println(f.getAbsolutePath());
Hope I helped.
•
•
Join Date: Feb 2008
Posts: 100
Reputation:
Solved Threads: 5
0
#10 Oct 16th, 2009
Did you try my idea bellow?
import java.io.File then use this code:
This will tell you the absolute path of the folder in which the java app is running (the "*.jar" file).
import java.io.File then use this code:
Java Syntax (Toggle Plain Text)
File f = new File("./"); System.out.println(f.getAbsolutePath());
![]() |
Similar Threads
- How to run java file from browser (Java)
- How to kill the running .jar file from another jar in java? (Java)
- is it possible to link a java file? (Java)
- How can i suppress a user prompt while running a batch file in windows 2000 machin (Windows NT / 2000 / XP)
- How can i capture a crash while running a batch file? (Windows NT / 2000 / XP)
- Error running Java (Java)
- error while running jar file (Java)
- How to create an exe for a Java application (Java)
Other Threads in the Java Forum
- Previous Thread: possible loss of precision error for obtaining sum, average, etc..
- Next Thread: jdk version
| Thread Tools | Search this Thread |
Tag cloud for Java
android api appinventor apple applet application arc arguments array arrays automation binary bluetooth c++ chat class classes client code codesnippet compiler component csv database doctype draw ebook eclipse error event exception fractal freeze game givemetehcodez graphics gui html ide image input integer intellij iphone j2me java java.xls javaprojects jni jpanel julia linux list login loop loops mac map method methods mobile netbeans newbie number online oracle page parameter print problem program programming project recursion reporting rotatetext scanner screen server set size sms socket sort sourcelabs sql string superclass swing system template test testautomation threads time title tree tutorial-sample windows working





