• Post Reply Bookmark Topic Watch Topic
  • New Topic

Getting information about where class file is stored based on object  RSS feed

 
Harish Tiruvile
Ranch Hand
Posts: 99
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi all

Is it possible to retrive information about where class file is stored in my system\computer based on Object reference..

I mean i am having an object say "Student"

through java program i should print where exactly that Student.java file is placed in my system like C:\javaprgs\Student.java

Is it possible to do so?...
 
Peter Chase
Ranch Hand
Posts: 1970
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Generally, no, you simply can't get that information. Java does not store the path of the original source file in the class.

In theory, I suppose, one might be able to write a custom ClassLoader that would make this type of thing possible. You'd have to [i]really[/] need the facility, before that was worthwhile, I'd say.

Can you explain what you are trying to achieve, in case there is another approach that would be better?
 
Harish Tiruvile
Ranch Hand
Posts: 99
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Thank you Peter,

While reading already written java codes i am spending more time in searching for exact file path(because in import they have used .* and i am having many import statements)..so i want to create a program which helps me in finding out class path (just by giving Object instance)
 
Ernest Friedman-Hill
author and iconoclast
Sheriff
Posts: 24217
38
Chrome Eclipse IDE Mac OS X
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
It sounds like what you need is to use a better editor or development environment. All serious Java programmer's editors and especially all IDEs let you click on an imported class name and automatically open that source file in the editor. Time to retire Notepad, and move to, for example Eclipse.
 
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!