• Post Reply Bookmark Topic Watch Topic
  • New Topic

Using class.getResource() on Different Drives  RSS feed

 
Scott Florez
Ranch Hand
Posts: 58
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
I'm currently using class.getResource() to read an RTF file into a JEditorPane. It works fine with the RTF file in the working or a relative directory, but I cannot figure out how to read an RTF file from another drive. Everything I've tried gives me an invalid URL error. Is there another method I should be using? Here's the working code for when the file is in the current directory:


[ March 26, 2007: Message edited by: Scott Florez ]
 
Joe Ess
Bartender
Posts: 9426
12
Linux Mac OS X Windows
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
So what code are you using that doesn't work?
Are you aware that resources loaded by class.getResource() must be in the CLASSPATH?
 
Scott Florez
Ranch Hand
Posts: 58
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
I didn't know they need to be in the classpath. Is there another method I can use to serve the same purpose? I'm wanting to load documents from a mapped drive on the server.
 
Joe Ess
Bartender
Posts: 9426
12
Linux Mac OS X Windows
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
JEditorPane has several methods one can use to set what is displayed. For example, you could pass the URL for the file as a String, read the content in and pass it to JEditorPane for rendering, or create a java.net.URL instance and pass it that. It all depends on what your requirements are.
 
Scott Florez
Ranch Hand
Posts: 58
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Thanks for your replies Joe. I'm still a bit confused as to how to read a file into a JEditorPane from a mapped network drive. Perhaps you could give me an example line of code? Let's say I'm trying to render an RTF file in a JEditorPane from the location s:\documents\mydocument.rtf. Could you show me how I can get this into my JEditorPane? Thanks!
 
Joe Ess
Bartender
Posts: 9426
12
Linux Mac OS X Windows
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
pane.setPage("file:///s:/documents/mydocument.rtf");
 
Scott Florez
Ranch Hand
Posts: 58
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Thanks Joe. I guess I was trying to add in an extra method that I didn't need. It all seems to be working right now. Thanks!!!
 
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!