• Post Reply Bookmark Topic Watch Topic
  • New Topic

conversion to binary name  RSS feed

 
Hardik Raja
Ranch Hand
Posts: 117
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
hi,

how about to convert a path(Eg "c:\abc\xyz.class")entered by user through console to binary name so that it can be used in the loadClass method as an argument
i am very thankfull to everyone raeding and replying for this post.

thanks,
hardik
 
Peter Chase
Ranch Hand
Posts: 1970
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
I'm not sure what you mean by "binary name". That's not a recognised term in Java, I think. I am guessing that what you want is the class name.

If so, you have a problem. If you want the system ClassLoader to load them, then class files have to be in a directory structure, where the each subdirectory name corresponds to an element of the Java package name. But you can't tell, just from a single file path, which of the directories in the path are parts of the package name, and which are part of the base directory of your class file hierarchy.

If possible, you need to re-specify your requirement, so the base directory is specified separately to the rest of the path. If you're not allowed to do that, perhaps you can invent some heuristic like "the first element of the package is always 'com' or 'org' or whatever".
 
Hardik Raja
Ranch Hand
Posts: 117
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
binary name format is

eg.
java.awt.Button.class
 
luc comeau
Ranch Hand
Posts: 97
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
maybe something along the lines of :
tokenize the incomming path name from the consol by "\", then take each token and build a String , go through each token and add a period to the end of it(except for th last token).

I'm not exactly sure if you can use a string as the "binary name", but im surethis could be done with something along these lines, assuming you already know where to load this binary name from?
-Luc
 
Consider Paul's rocket mass heater.
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!