Results 1 to 8 of 8
- 04-11-2012, 07:11 PM #1
Member
- Join Date
- Apr 2012
- Posts
- 7
- Rep Power
- 0
JAR, .txt and .wav file in Netbeans!
Hi guys,
I'm making (or just finished making) a program in Java on Netbeans which has a GUI and uses .txt and .wav files for different purposes. The problem I have is when I create the JAR file and use it on a DIFFERENT computer, it doesn't contain these files within it, even though I've placed them in the build folder of the project itself. Am I doing this right? Should it be placed somewhere else?
Hoping someone can help!
Thanks!
- 04-11-2012, 07:51 PM #2
Re: JAR, .txt and .wav file in Netbeans!
Moved from New to Java
dbWhy do they call it rush hour when nothing moves? - Robin Williams
- 04-12-2012, 09:34 AM #3
Moderator
- Join Date
- Apr 2009
- Posts
- 10,476
- Rep Power
- 16
Re: JAR, .txt and .wav file in Netbeans!
I usually stick resources in a resources folder (or whatever you want to call it) and mark that folder as a src folder.
Netbeans will then include anything in that folder in the jar file.
Hopefully you are accessing these files using getResource/getResourceAsStream?Please do not ask for code as refusal often offends.
- 04-12-2012, 01:32 PM #4
Member
- Join Date
- Apr 2012
- Posts
- 7
- Rep Power
- 0
Re: JAR, .txt and .wav file in Netbeans!
No I'm not using the getResource/getResourceAsStream, I don't even know what that is and was using code similar to whats here* to write and read form my .txt files. I'll have a look into getResource/getResourceAsStream and post back if I have any luck! Thanks!
*Java Write To File,Java Write to File Example,Write to File in Java,How to Write to File
- 04-12-2012, 02:41 PM #5
Moderator
- Join Date
- Apr 2009
- Posts
- 10,476
- Rep Power
- 16
Re: JAR, .txt and .wav file in Netbeans!
The first thing is to get the files in the correct place so they get jarred up with the rest of your code.
(This assumes these are read only files).
It's at that point you will find that you can't use "normal" paths to read those files, so you need to use the getResourceAsStream (etc) to get at them.
Use the method found on Class, not on ClassLoader.
So:
Java Code:YourClass.class.getResourceAsStream("wherever the resource is in the jar file");Please do not ask for code as refusal often offends.
- 04-12-2012, 02:47 PM #6
Re: JAR, .txt and .wav file in Netbeans!
That tutorial you linked is on a crappy site which has more bad code examples than good. I strongly recommend that you follow the Oracle tutorials.
You'll find some discussion of using getResource(...) in the section on How to Use Icons (The Java™ Tutorials > Creating a GUI With JFC/Swing > Using Swing Components) -- the idea is the same whether it's an image file or your text/audio files.
dbWhy do they call it rush hour when nothing moves? - Robin Williams
- 04-13-2012, 09:28 AM #7
Moderator
- Join Date
- Apr 2009
- Posts
- 10,476
- Rep Power
- 16
Re: JAR, .txt and .wav file in Netbeans!
I didn't notice it was flowery-subcontinent.
No wonder they're having problems...Please do not ask for code as refusal often offends.
- 04-13-2012, 12:28 PM #8
Similar Threads
-
Jar file in NetBeans
By bochra in forum NetBeansReplies: 0Last Post: 01-30-2011, 01:15 PM -
File access outside Netbeans
By TimHuey in forum NetBeansReplies: 6Last Post: 08-30-2009, 08:52 PM -
How to create .war file in NetBeans 6.1
By shuklajayb in forum NetBeansReplies: 0Last Post: 12-21-2008, 03:58 PM -
cudnt run jar file builded in netbeans!
By pranav13 in forum NetBeansReplies: 2Last Post: 10-09-2008, 04:29 AM -
file not found outside of Netbeans
By annie in forum NetBeansReplies: 0Last Post: 06-21-2008, 10:10 PM


LinkBack URL
About LinkBacks
Reply With Quote

Bookmarks