Win a copy of Programmer's Guide to Java SE 8 Oracle Certified Associate (OCA) this week in the OCAJP forum!
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

Can you explain me this code ??

 
ankur rathi
Ranch Hand
Posts: 3830
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator


what this code is doing ?

please help ..

thanks a lot .
 
Stephen Huey
Ranch Hand
Posts: 618
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Taking a stab even though I've never used any of that really...when you give the ClassLoader the name of the resource, it know where to find it, and gives you the URL so that you can get ahold of it directly. So then you get a file handle to it based on that URL...

I didn't check any of the other code, but that getFile() method did jump out at me...just want you to be sure that file is a String, not a File, because it looks like the getFile() method returns a String of the file's name:
http://java.sun.com/j2se/1.3/docs/api/java/net/URL.html
[ February 01, 2005: Message edited by: Stephen Huey ]
 
David Harkness
Ranch Hand
Posts: 1646
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Sounds right, but I haven't used those much either. Normally, getResource(String) is used to locate a file (image, properties, etc) in the classpath. But beware that sometimes that resource is packaged up into a JAR on the classpath. In that case, the URL returned will have a "#resource" at the end, meaning it won't point to a file but rather a resource inside a file.

In other words, that code will not work if the resource is in a JAR. There is, of course, one way to find out . . . try it!
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic