You should include the wav file inside your application jar. This way you won't have to manage the copy of the file in the user's file system (keep in mind that, for example, in UNIX, Mac, etc. you can't access to the hard drive through C:/...
).
For example, if you place the wav file in the root of the app jar (app.jar/samp.wav
):
InputStream is = getClass().getClassLoader().getResourceAsStream("samp.wav");
or, if you had a "sounds" directory in the app jar root (app.jar/sounds/samp.wav
):
InputStream is = getClass().getClassLoader().getResourceAsStream("sounds/samp.wav");
Check this post for extra information about playing wav files with Java (though for your question, I think you have already solved this problem). Consider as well playing it in a separate thread. Check also this web for examples about managing media files in Java.
与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…