2014-08-27 45 views
0

好吧,我得到這個使用Files.toCopy的方法的錯誤,它說該文件已被使用。無法複製音頻文件

Files.copy(tempClip.toPath(),wavFile.toPath(),StandardCopyOption.REPLACE_EXISTING);

這是打開文件的方法。當我不使用這種方法時,它複製得很好,當我使用這種方法時,它會給出錯誤。下面的current.track引用上面的wavFile。我以爲我用audioStream.close()和audioClip.close()來關閉所有的文件。

if (e.getSource() instanceof QuoteButton) { 
     QuoteButton current = (QuoteButton)e.getSource(); 
     try { 
      audioStream = AudioSystem.getAudioInputStream(current.track); 
      AudioFormat format = audioStream.getFormat(); 
      DataLine.Info info = new DataLine.Info(Clip.class, format); 
      audioClip = (Clip) AudioSystem.getLine(info); 
      audioClip.open(audioStream); 
      audioClip.start(); 

      audioClip.addLineListener(new LineListener() { 
       @Override 
       public void update(LineEvent event) { 
        if(event.getType() == LineEvent.Type.STOP){ 
         audioClip.close(); 
        } 
       } 
      }); 
      audioStream.close(); 

     } catch (UnsupportedAudioFileException | IOException | LineUnavailableException e1) { 
      e1.printStackTrace(); 
     } 
    } 

回答

0

你的聽衆關閉音頻剪輯所以它實際上沒有叫,直到你得到LineEvent.Type.STOP

+0

我嘗試在其他位置使用audioClip.close() – 2014-08-27 22:28:32

0

沒關係我有一個隱私泄露。修復。