我已经阅读了一些问题,如何访问Android项目中的内部文件,但它们是以InputStream格式提供的。我只想访问文件夹以将其传递给外部类。无论我尝试什么,我都会收到FileNotFoundException错误。
这是我想要访问音频文件的代码部分:
//Read wav files function (implements WavFile Class)
void readBackground(String file){
try
{
//Create a wavFile class from the specified file
WavFile wavFile = WavFile.openWavFile(new File("res/raw/"+file));
// Get the number of audio data samples in the wav file
long size = wavFile.getNumFrames();
// Create a reading buffer
double[] buffer = new double[(int)size];
int framesRead;
do
{
//Read wav file
framesRead = wavFile.readFrames(buffer, (int)size);
}
while (framesRead != 0);
//Call to the function for global background array allocation
setArrayBackground(buffer);
//Close wav file
wavFile.close();
}
catch (Exception e)
{
System.err.println(e);
}
}
想法?
我也尝试过方法getAbsolutePath()但没有成功。