Win a copy of Kotlin in Action this week in the Kotlin forum!
  • Post Reply Bookmark Topic Watch Topic
  • New Topic

How can I make ref to the file outside?  RSS feed

 
Max Bean
Ranch Hand
Posts: 31
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Suppose I have:

URL url = MyClass.class.getResource("test.txt");

I notice I can get url if and only if I place 'test.txt' in the same folder wif the compiled MyClass.class.

What if I need to place 'test.text' anywhere else?

Thnx
 
Abhinav Srivastava
Ranch Hand
Posts: 354
Eclipse IDE Java Oracle
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
it should be in your classpath. e.g.
C:\test\com\xyz\test.txt
and c:\test is in your classpath, then
use it as MyClass.class.getClassloader().getResource("com/xyz/test.txt");
 
It is sorta covered in the JavaRanch Style Guide.
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!