Results 1 to 8 of 8
  1. #1
    psv
    psv is offline Member
    Join Date
    Apr 2012
    Posts
    7
    Rep Power
    0

    Angry 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!

  2. #2
    DarrylBurke's Avatar
    DarrylBurke is offline Forum Police
    Join Date
    Sep 2008
    Location
    Madgaon, Goa, India
    Posts
    11,458
    Rep Power
    20

    Default Re: JAR, .txt and .wav file in Netbeans!

    Moved from New to Java

    db
    If you're forever cleaning cobwebs, it's time to get rid of the spiders.

  3. #3
    Tolls is offline Moderator
    Join Date
    Apr 2009
    Posts
    12,224
    Rep Power
    20

    Default 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.

    ** This space for rent **

  4. #4
    psv
    psv is offline Member
    Join Date
    Apr 2012
    Posts
    7
    Rep Power
    0

    Default 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

  5. #5
    Tolls is offline Moderator
    Join Date
    Apr 2009
    Posts
    12,224
    Rep Power
    20

    Default 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.

    ** This space for rent **

  6. #6
    DarrylBurke's Avatar
    DarrylBurke is offline Forum Police
    Join Date
    Sep 2008
    Location
    Madgaon, Goa, India
    Posts
    11,458
    Rep Power
    20

    Default 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.

    db
    If you're forever cleaning cobwebs, it's time to get rid of the spiders.

  7. #7
    Tolls is offline Moderator
    Join Date
    Apr 2009
    Posts
    12,224
    Rep Power
    20

    Default 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.

    ** This space for rent **

  8. #8
    DarrylBurke's Avatar
    DarrylBurke is offline Forum Police
    Join Date
    Sep 2008
    Location
    Madgaon, Goa, India
    Posts
    11,458
    Rep Power
    20

    Default Re: JAR, .txt and .wav file in Netbeans!

    Quote Originally Posted by Tolls View Post
    I didn't notice it was flowery-subcontinent.
    /goes outside to smell the flowers

    db <-- from the subcontinent
    If you're forever cleaning cobwebs, it's time to get rid of the spiders.

Similar Threads

  1. Jar file in NetBeans
    By bochra in forum NetBeans
    Replies: 0
    Last Post: 01-30-2011, 02:15 PM
  2. File access outside Netbeans
    By TimHuey in forum NetBeans
    Replies: 6
    Last Post: 08-30-2009, 09:52 PM
  3. How to create .war file in NetBeans 6.1
    By shuklajayb in forum NetBeans
    Replies: 0
    Last Post: 12-21-2008, 04:58 PM
  4. cudnt run jar file builded in netbeans!
    By pranav13 in forum NetBeans
    Replies: 2
    Last Post: 10-09-2008, 05:29 AM
  5. file not found outside of Netbeans
    By annie in forum NetBeans
    Replies: 0
    Last Post: 06-21-2008, 11:10 PM

Tags for this Thread

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •