将(WAV)写入文件只能说一个单词(最后一个单词)

时间:2016-10-06 02:30:23

标签: java file audio

我使用了WritetoFile()方法,因为我的单词数组使用了blockingPlay,但是,当我在文件系统中回放文件thisisatest_pause.wav时,它只播放数组中的最后一个单词,即"测试&#34 ;.完整的短语是"这是一个测试"参数指定暂停。这是代码

public void play(int pause, String filename, String path) throws InterruptedException {
    // play the words in order
    for (int i = 0; i < numWords; i++) {
        myWordArray[i].blockingPlay();
        Thread.sleep(pause);
        try {
        myWordArray[i].writeToFile("C:\\Users\\Justin\\Desktop\\JavaMedia\\thisisatest_pause.wav\\");
        } catch (SoundException e){
        System.out.println("Error" +e);

      }
        }
    }

1 个答案:

答案 0 :(得分:-1)

因为循环中的每次迭代都会写入 相同的 文件名。

我不知道myWordArray [i]是什么类型的对象,但是我的通灵能力告诉我,如果文件已经存在,writeToFile的实现会覆盖该文件。