Win a copy of Practical SVG this week in the HTML/CSS/JavaScript forum!
  • Post Reply Bookmark Topic Watch Topic
  • New Topic

Trouble getting to a file

 
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: 20822
68
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.
 
Montana has cold dark nights. Perfect for the heat from incandescent light. Tiny ad:
the new thread boost feature brings a LOT of attention to your favorite threads
https://coderanch.com/t/674455/Thread-Boost-feature
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!