1
我是一個java中的完整新手,有人可以告訴我把wav文件名放在下面的代碼中,我的文件名是「p.wav」,它的位置是D:/ p。 WAV; plz幫助,我得到以下無差錯:在java中讀取wav文件
異常在線程 「主要」 java.lang.Error的:
未解決的編譯問題:
WavFile不能被解析爲一個類型
WavFile解決不了
import java.io.*;
public class ReadExample
{
public static void main(String[] args)
{
try
{
// Open the wav file specified as the first argument
WavFile wavFile = WavFile.openWavFile(new File(args[0]));
// Display information about the wav file
wavFile.display();
// Get the number of audio channels in the wav file
int numChannels = wavFile.getNumChannels();
// Create a buffer of 100 frames
double[] buffer = new double[100 * numChannels];
int framesRead;
double min = Double.MAX_VALUE;
double max = Double.MIN_VALUE;
do
{
// Read frames into buffer
framesRead = wavFile.readFrames(buffer, 100);
// Loop through frames and look for minimum and maximum value
for (int s=0 ; s<framesRead * numChannels ; s++)
{
if (buffer[s] > max) max = buffer[s];
if (buffer[s] < min) min = buffer[s];
}
}
while (framesRead != 0);
// Close the wavFile
wavFile.close();
// Output the minimum and maximum value
System.out.printf("Min: %f, Max: %f\n", min, max);
}
catch (Exception e)
{
System.err.println(e);
}
}}
你有一個叫做'WavFile'對象?它屬於一個圖書館嗎? – Sionnach733
您必須導入包含WavFile的庫來解決編譯問題。從控制檯運行程序時,應將文件的名稱作爲第一個參數。 – gawi
@gawi我使用eclipse來運行我的代碼,你可以告訴我如何添加文件名 – user3262269