• Post Reply Bookmark Topic Watch Topic
  • New Topic

Trouble getting to a file  RSS feed

 
Darrin Smith
Ranch Hand
Posts: 276
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
I have an xslt file that I need to read in. The directory structure looks like this:

NetbeansProjects
>CustomerService
>>build
>>>classes
>>>>customerservice
>>>>>MAIN CLASS IS HERE
>>>>>com
>>>>>>mycorp
>>>>>>>myservice
>>>>>>>>proxy
>>>>>>>>>customer
>>>>>>>>>>ALL THE CLASS FILES ARE HERE
>>>>>resources (note, same level as customerservice under classes)
>>>>>>myfile.xslt


I've tried using getResourceAsStream to no avail. What I have tried is:



When I run it I get this:

Could not find file: \myfile.xslt
Current locaiton is: C:\NetBeansProjects\CustomerService\.

What am I doing wrong?

 
Darrin Smith
Ranch Hand
Posts: 276
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Got it.

Need to use:

URL url = Thread.currentThread().getContextClassLoader().getResource(DEFAULT_XSLT_FILE);

and also prefix the file with the root directory like this:

private static final String DEFAULT_XSLT_FILE = "resources/ClcsProxyRetrieveCustomerResponseFilter.xslt";
 
Rob Spoor
Sheriff
Posts: 20898
81
Chrome Eclipse IDE Java Windows
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Resources always work with /, so replace File.separator with that.
 
It is sorta covered in the JavaRanch Style Guide.
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!