Hallo,
ich bin völliger Neuling in Java.
Zuerst mal: Gibts in Netbeans ne Möglichkeit die Fehlermeldungen zu kopieren?
(um in ein Forum oder google zu pasten)
Im Code untenmöchte ich einen FileStream schliessen, jedoch zeigt Netbeans eine Fehlermeldung:
unreported exception java.io.IOException; must be caught or declared to be thrown
Muss ich jetzt due close methode im finally block selbst in ein try blocjk setzen? das scheint mir aber extrem unnötig kompliziert zu sein (vorallem auch um den code zu verstehen) oder muss ich einfach dei blöcke anders anordnen?
P.S:
as.close() hat das gleiche problem.
ich bin völliger Neuling in Java.
Zuerst mal: Gibts in Netbeans ne Möglichkeit die Fehlermeldungen zu kopieren?
(um in ein Forum oder google zu pasten)
Im Code untenmöchte ich einen FileStream schliessen, jedoch zeigt Netbeans eine Fehlermeldung:
unreported exception java.io.IOException; must be caught or declared to be thrown
Muss ich jetzt due close methode im finally block selbst in ein try blocjk setzen? das scheint mir aber extrem unnötig kompliziert zu sein (vorallem auch um den code zu verstehen) oder muss ich einfach dei blöcke anders anordnen?
Java:
public void honk (){
//** add this into your application code as appropriate
// Open an input stream to the audio file.
InputStream in = null;
try {
in = new FileInputStream(
"C:/Car horn.wav");
// Create an AudioStream object from the input stream.
AudioStream as = null;
as = new AudioStream(in);
// Use the static class member "player" from class AudioPlayer to play
// clip.
AudioPlayer.player.start(as);
}
catch (FileNotFoundException ex) {
System.out.println("FileNotFoundException: " + ex.getMessage());
}
catch (IOException ex) {
System.out.println("IOException: " + ex.getMessage());
}
finally{
if(in!= null)
[B]in.close();[/B]
}
P.S:
as.close() hat das gleiche problem.