`不是WAVE文件-没有RIFF标头`锁定文件 [英] `Not a WAVE file - no RIFF header` locks file
问题描述
使用代码:
using (var reader = new WaveFileReader(audioFileLocation))
{
// Do something....
}
如果给出了引发异常的wav文件:
If given a wav file that throws the exception:
不是WAVE文件-没有RIFF标头
异常详细信息:System.FormatException:不是WAVE文件-没有RIFF标头
Not a WAVE file - no RIFF header
Exception Details: System.FormatException: Not a WAVE file - no RIFF header
它锁定文件audioFileLocation
,以防止其被删除.
It locks the file audioFileLocation
which prevents it from being deleted.
在使用阅读器之前,有什么方法可以检查是否存在有效的RIFF标头?
Is there any way to check for the existence of a valid RIFF header before using the reader?
推荐答案
尝试使用流:
using(var inputStream = new FileStream(audioFileLocation, FileMode.Open,
FileAccess.Write, FileShare.ReadWrite))
{
using (var reader = new WaveFileReader(inputStream))
{
// Do something....
}
}
如果 THIS 是当前代码在构造器的字符串重载"中使用File.OpenRead(waveFile)
的WaveFileReader
类,返回的Stream
似乎没有被关闭/处置.也许已经是后续作品了:
If THIS is the current code of the WaveFileReader
class it uses File.OpenRead(waveFile)
in the "string overload" of the consturctor and the Stream
returned seems not to be closed/disposed. Maybe already the follownin works:
using(var inputStream = File.OpenRead(audioFileLocation))
{
using (var reader = new WaveFileReader(inputStream))
{
// Do something....
}
}
因为这应该处理流.
这篇关于`不是WAVE文件-没有RIFF标头`锁定文件的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!