AppletTalk.com Forum Index AppletTalk.com
Java discussions newsgroups
 
Archives   FAQFAQ   SearchSearch   MemberlistMemberlist   UsergroupsUsergroups   RegisterRegister 
 ProfileProfile   Log in to check your private messagesLog in to check your private messages   Log inLog in 

Loading an external file as resource

 
Post new topic   Reply to topic    AppletTalk.com Forum Index -> Java Help
View previous topic :: View next topic  
Author Message
Allan Bruce
Guest





PostPosted: Sun Jan 15, 2006 3:27 pm    Post subject: Loading an external file as resource Reply with quote



I want to be able to play small audio files from my apllication but I am
having problems locating the files. I want this to be successful whether I
am running from the class files or a jar file. What is the best way to do
this? I am currently trying to load the files using this method:

URL lFileURL = AudioPlayer.class.getResource("/Sounds/" + xiFile);

but it doesnt seem to work.
Thanks
Allan


Back to top
opalpa@gmail.com opalinsk
Guest





PostPosted: Sun Jan 15, 2006 5:06 pm    Post subject: Re: Loading an external file as resource Reply with quote



Put the Sounds directory inside the directory holding AudioPlayer class
then access it with getResource("Sounds/"+xiFile)

This will work from jars or outside of jars.

Opalinski
[email]opalpa (AT) gmail (DOT) com[/email]
http://www.geocities.com/opalpaweb/

Back to top
opalpa@gmail.com opalinsk
Guest





PostPosted: Sun Jan 15, 2006 5:12 pm    Post subject: Re: Loading an external file as resource Reply with quote



Also consider replacing the "/" with java.io.File.separator for cross
platform-ness.

Opalinski
[email]opalpa (AT) gmail (DOT) com[/email]
http://www.geocities.com/opalpaweb/

Back to top
Roedy Green
Guest





PostPosted: Sun Jan 15, 2006 11:04 pm    Post subject: Re: Loading an external file as resource Reply with quote

On 15 Jan 2006 09:12:37 -0800, "opalpa (AT) gmail (DOT) com opalinski from
opalpaweb" <opalpa (AT) gmail (DOT) com> wrote, quoted or indirectly quoted
someone who said :

Quote:
Also consider replacing the "/" with java.io.File.separator for cross
platform-ness.

I know that both / and \ work on windows. Is it true that / is safe
for all platforms?
--
Canadian Mind Products, Roedy Green.
http://mindprod.com Java custom programming, consulting and coaching.

Back to top
opalpa@gmail.com opalinsk
Guest





PostPosted: Sun Jan 15, 2006 11:34 pm    Post subject: Re: Loading an external file as resource Reply with quote

Looked into this a little. Class.getResource passes work off to
ClassLoader.getResource which passes it off beyond sources available to
me. I looked at ClassLoader.getResource documentation and to my
suprise it said that the path passed in is to be "/" seperated because
these things are done via URL and not file path. Here is link to
documentation:
[url]http://java.sun.com/j2se/1.4.2/docs/api/java/lang/ClassLoader.html#getResource(java.lang.String[/url])

I believe this means my second email recommeding File's separator is
incorrect and that "/" is to be used according to documentaiton.

Thanks for pointing to this Roedy; I wouldn't have given it more
thought without your message.

Opalinski
[email]opalpa (AT) gmail (DOT) com[/email]
http://www.geocities.com/opalpaweb/

Back to top
Roedy Green
Guest





PostPosted: Mon Jan 16, 2006 12:06 am    Post subject: Re: Loading an external file as resource Reply with quote

On 15 Jan 2006 15:34:38 -0800, "opalpa (AT) gmail (DOT) com opalinski from
opalpaweb" <opalpa (AT) gmail (DOT) com> wrote, quoted or indirectly quoted
someone who said :

Quote:
Thanks for pointing to this Roedy; I wouldn't have given it more
thought without your message.

I will reask the question in terms of new File( ). Will it take "/"
on every platform?
--
Canadian Mind Products, Roedy Green.
http://mindprod.com Java custom programming, consulting and coaching.

Back to top
Allan Bruce
Guest





PostPosted: Mon Jan 16, 2006 12:54 am    Post subject: Re: Loading an external file as resource Reply with quote


"Roedy Green" <my_email_is_posted_on_my_website (AT) munged (DOT) invalid> wrote in
message news:drols1hda4l8cki6ao0k55mm23mt6s3ms2 (AT) 4ax (DOT) com...
Quote:
On 15 Jan 2006 15:34:38 -0800, "opalpa (AT) gmail (DOT) com opalinski from
opalpaweb" <opalpa (AT) gmail (DOT) com> wrote, quoted or indirectly quoted
someone who said :

Thanks for pointing to this Roedy; I wouldn't have given it more
thought without your message.

I will reask the question in terms of new File( ). Will it take "/"
on every platform?

From what I know, yes that should work. I remember reading something
stating this but cant for the life of me find it now...
Allan



Back to top
Display posts from previous:   
Post new topic   Reply to topic    AppletTalk.com Forum Index -> Java Help All times are GMT
Page 1 of 1

 
Jump to:  
You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum
You cannot vote in polls in this forum


Powered by phpBB © 2001, 2006 phpBB Group
SEO toolkit © 2004-2006 webmedic.