Java Forums

Main Menu
Home
Today's Posts
FAQ
Search
Contact Us

Java Network
Linux Archive
Java Tips
Java Tips Blog

Sponsored Links





Welcome to the Java Forums.

You are currently viewing our boards as a guest which gives you limited access to view most discussions and access our other features. By joining our free community, you will:

  • have access to post topics
  • communicate privately with other members (PM)
  • not see advertisements between posts
  • have the possibility to earn one of our surprises if you are an active member
  • access many other special features that will be introduced later.

Registration is fast, simple and absolutely free so please, join our community today!

If you have any problems with the registration process or your account login, please contact us.

Reply
 
LinkBack Thread Tools Display Modes
  #1 (permalink)  
Old 04-26-2007, 06:21 PM
Member
 
Join Date: Apr 2007
Location: Pennsylvania,USA
Posts: 46
sandor is on a distinguished road
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
Code:
package test; public class TestingClassName { public static void main(String[] args) { System.out.println( TestingClassName.class.getName().replaceAll(".", "/") + ".class"); } }
Bookmark Post in Technorati
Reply With Quote
Sponsored Links
  #2 (permalink)  
Old 04-26-2007, 06:30 PM
Member
 
Join Date: Apr 2007
Location: Indiana
Posts: 84
pegitha is on a distinguished road
Send a message via Skype™ to pegitha
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.
Bookmark Post in Technorati
Reply With Quote
  #3 (permalink)  
Old 04-26-2007, 06:31 PM
Member
 
Join Date: Apr 2007
Location: Pennsylvania,USA
Posts: 46
sandor is on a distinguished road
Thanks for the help. What would I use if the system does not use a slash?
Bookmark Post in Technorati
Reply With Quote
  #4 (permalink)  
Old 04-26-2007, 06:45 PM
Member
 
Join Date: Apr 2007
Location: Indiana
Posts: 84
pegitha is on a distinguished road
Send a message via Skype™ to pegitha
If you use 5.0 do this:
Code:
TestingClassName.class.getName().replaceAll("\\.", Matcher.quoteReplacement(File.separator)) + ".class");
If you are using an earlier version use the String replace I guess.
Bookmark Post in Technorati
Reply With Quote
  #5 (permalink)  
Old 08-12-2008, 03:38 PM
Member
 
Join Date: Aug 2008
Posts: 11
g25451 is on a distinguished road
how are you
Bookmark Post in Technorati
Reply With Quote
Sponsored Links
Reply


Thread Tools
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

vB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On


Similar Threads
Thread Thread Starter Forum Replies Last Post
Setting up class path for Eclipse tsantana Eclipse 1 04-07-2008 09:05 PM
Specify path borgrodrick Eclipse 1 02-13-2008 01:03 AM
Log4J.jar in class path eva New To Java 0 01-02-2008 08:39 PM
problem with PATH creativehacker New To Java 4 07-11-2007 04:54 PM
Specifying absolute path in web.xml Felissa JavaServer Pages (JSP) and JSTL 1 07-05-2007 08:56 AM


All times are GMT +3. The time now is 02:17 AM.


VBulletin, Copyright ©2000 - 2008, Jelsoft Enterprises Ltd.
Content Relevant URLs by vBSEO ©2007, Crawlability, Inc.
Copyright ©2006 - 2007, www.java-forums.org