| | |
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: 99
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: 99
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 |
-xlint add android api applet application array arrays automation bi binary blackberry bluetooth chat class classes client code compile compiler component converter database digit eclipse equation error event exception fractal freeze functiontesting game gameprogramming givemetehcodez graphics gui health html hyper ide idea image input int integer j2me java javame javaprojects jetbrains jni jpanel jtable julia learningresources linux list login loop main map method methods mobile myregfun netbeans newbie nonstatic notdisplaying page pearl print problem program programming project qt recursion scanner screen scrollbar server set size sms sort spamblocker sql string superclass swing system thread threads time tree variablebinding windows xor





