Results 1 to 5 of 5
Thread: trying to get class name & path
- 04-26-2007, 04:21 PM #1
Member
- Join Date
- Apr 2007
- Location
- Pennsylvania,USA
- Posts
- 45
- Rep Power
- 0
trying to get class name & path
I need to get the name and path of some of my classes and am having an issue.
this code looks like it should work but give me an out put of:
/////////////////////.class
Java Code:package test; public class TestingClassName { public static void main(String[] args) { System.out.println( TestingClassName.class.getName().replaceAll(".", "/") + ".class"); } }
- 04-26-2007, 04:30 PM #2
Member
- Join Date
- Apr 2007
- Location
- Indiana
- Posts
- 83
- Rep Power
- 0
what version of java are you using ?Are you using 5.0 or higher?
YOu can change you code to this:
TestingClassName.class.getName().replaceAll("\\.", "/") + ".class");
and escaping it with a "\\". In regex "." means replace everything so that is why all characters are replaced with "\". you also need to escape the "\" which is why I put in two.
If you are using java 5.0 there is a new class you can use:java.util.regex.Pattern.quote
But not all file systems use the "/" so you need to be careful with this.
- 04-26-2007, 04:31 PM #3
Member
- Join Date
- Apr 2007
- Location
- Pennsylvania,USA
- Posts
- 45
- Rep Power
- 0
Thanks for the help. What would I use if the system does not use a slash?
- 04-26-2007, 04:45 PM #4
Member
- Join Date
- Apr 2007
- Location
- Indiana
- Posts
- 83
- Rep Power
- 0
If you use 5.0 do this:
If you are using an earlier version use the String replace I guess.Java Code:TestingClassName.class.getName().replaceAll("\\.", Matcher.quoteReplacement(File.separator)) + ".class");
- 08-12-2008, 01:38 PM #5
Member
- Join Date
- Aug 2008
- Posts
- 11
- Rep Power
- 0
Similar Threads
-
Setting up class path for Eclipse
By tsantana in forum EclipseReplies: 1Last Post: 04-07-2008, 07:05 PM -
Specify path
By borgrodrick in forum EclipseReplies: 1Last Post: 02-12-2008, 11:03 PM -
Log4J.jar in class path
By eva in forum New To JavaReplies: 0Last Post: 01-02-2008, 06:39 PM -
problem with PATH
By creativehacker in forum New To JavaReplies: 4Last Post: 07-11-2007, 02:54 PM -
Specifying absolute path in web.xml
By Felissa in forum JavaServer Pages (JSP) and JSTLReplies: 1Last Post: 07-05-2007, 06:56 AM


LinkBack URL
About LinkBacks
Reply With Quote
Bookmarks