java - Sound file not found, not in directory? -
I'm coding it in java and put the This is my This is then the form of an object in my second class to run If I am not mistaken, then I think everything is set up correctly but I got a If you are putting the file into Java square path (src folder) then you can load the sound file with the class path (reference) voice folder with
bgmusic Have given. Wav but there is still no identity in it. Am I doing something wrong?
voice category:
import java.applet.Applet; Import java.applet.AudioClip; Import java.io.file; Import java.net.MalformedURLException; Public Squared Sound {Private AudioClick MyClip; Public sound (string filename) {try {file file = new file (fileName); If (file.exists ()) {myClip = (AudioClip) applet.nuoudo clip (file.toURI () .toURL ()); } And {new runtime expiry ("sound: file not found:" + fileName); }} Hold (Malformedlexception E) {New Runtime Expansion ("Sound: Distorted URL:" + E); }} Public Zero Play () {myClip.play (); }}
bgmusic.wav :
string file name Has ran into = "BGMUSIC.WOW"; String Sounder = "." + File. Separator + "sound" + file. Separator; String filePath = soundDir + fileName; Sound bgMusic = new sound (file path); BgMusic.play ();
sound: file not found: ./sounds/bgmusic.wav which is returned in my
voice class with
throw exception because I have the
sounds folder to
./sounds/bgmusic. Must be correct as the subdirectory of the main Java folder passing through wav ?
new file (".") the base folder of your application (root Folder), so check your directory structure to see where the file is in relation to the file base folder. Otherwise, share your project structure.
Comments
Post a Comment