收费文件有问题

时间:2016-02-23 16:35:19

标签: java file clip

我在使用以下方法收取简单文件时遇到问题:

public class TrisGame extends Canvas implements Runnable{
...
public static void main(String[] args){
...
}
public final void chargeSound() throws FileNotFoundException{
        try{
            File click = new File("Click.wav");
            AudioInputStream clickc = AudioSystem.getAudioInputStream(click);
            Clip clip = AudioSystem.getClip();
            clip.open(clickc);
            if(ASX | AC | ADX | CSX | CC | CDX | BSX | BC | BDX){

                clip.loop(1);

            }
        }
        catch(UnsupportedAudioFileException | IOException | LineUnavailableException e){
            e.printStackTrace();
        }
}
public void run(){...}
}...

这是代码。输出是:

  

java.io.FileNotFoundException:   Click.wav   (Impossibile trovare il percorso specificato)at   java.io.FileInputStream.open0(Native Method)at   java.io.FileInputStream.open(FileInputStream.java:195)at   java.io.FileInputStream。(FileInputStream.java:138)at   com.sun.media.sound.WaveFloatFileReader.getAudioInputStream(WaveFloatFileReader.java:164)     在   javax.sound.sampled.AudioSystem.getAudioInputStream(AudioSystem.java:1181)     在trisgame.TrisGame.CaricaSuono(TrisGame.java:314)at   trisgame.TrisGame。(TrisGame.java:146)at   trisgame.TrisGame.main(TrisGame.java:154)建立成功(总计)   时间:7秒)

谢谢!

2 个答案:

答案 0 :(得分:0)

例外是java.io.FileNotFoundException ...

那么,你需要检查音频的路径是否正确??

答案 1 :(得分:0)

答案是在导入文件时需要包含整个文件路径和文件名,除非它在项目目录中。

如;

File click = new File( "C:\Users\(Username\Desktop\Click.wav" );
File click = new File( "src/resources/Click.wav" );