MP3文件读取的问题,如何读取最后128Byte的内容?
MP3文件读取的问题,如何读取最后128Byte的内容?
代码:
FileStream fs = File.OpenRead(strFilePath);
BinaryReader BR = new BinaryReader(fs);
FileInfo fi = new FileInfo(strFilePath);
byte[] buffer = BR.ReadBytes((int)fi.Length);
/********* 最后128Byte的内容 **********/
int i = buffer.Length - 128;
while( i < buffer.Length )
{
if( buffer[i] > 128 && i < buffer.Length - 1)
{
Console.WriteLine("{0}",Convert.ToChar( buffer[i] * 128 + buffer[i+1] ));
i++;
}
else if ( buffer[i] < 26 )
{
}
else
{
Console.Write("{0}",Convert.ToChar(buffer[i]));
}
i++;
}
//*****************************************/
我想先把最后128Byte的内容Console出来,但是问题有:
1、有没有一种办法能让我从文件任意位置开始读取内容
byte[] buffer = BR.ReadBytes((int)fi.Length);我个人认为这不是和好的办法
2、最后128Byte里的东西有中文的东西,怎么也读不出来了!!!!应该怎么搞定呢?半角的字符没问题哦
各位大虾帮帮忙吧,我才开始用C#就遇到这么大的难题
问题点数:100、回复次数:9Top
1 楼huleeyar(虚拟过客)回复于 2004-12-02 21:53:52 得分 0
关注
Top
2 楼huleeyar(虚拟过客)回复于 2004-12-02 21:54:12 得分 0
关注
Top
3 楼NIRVANAIII(问题人物)回复于 2004-12-02 22:21:55 得分 0
不是这样就沉了吧?
高手呢????
斑竹呢???Top
4 楼dazhu2(【倚天不出,谁与争锋】)回复于 2004-12-02 22:39:02 得分 100
FileStream myfs=new FileStream("f:\\1.mp3",System.IO.FileMode.Open ,System.IO.FileAccess.Read);
BinaryReader mybr=new BinaryReader(myfs,System.Text.Encoding.Default);
long file_len=myfs.Length;
int fl=int.Parse(file_len.ToString());
Console.WriteLine("文件长度为:--"+fl.ToString()+"Byte\r\n");
byte []box=new byte[fl];
byte []a;
if(fl>128)
{ a=new byte[128];
mybr.Read(box,0,fl);
//copy the data
Array.Copy(box,fl-128,a,0,128);
Console.WriteLine("文件长度为:--"+a.Length.ToString()+"Byte\r\n");
}
else
{
a=new byte[fl];
mybr.Read(a,0,fl);
}
myfs=new FileStream("f:\\dazhu.txt",System.IO.FileMode.Create,System.IO.FileAccess.Write);
BinaryWriter mysw=new BinaryWriter(myfs,System.Text.Encoding.Default);
mysw.Write(a);
mybr.Close();
myfs.Close();
zhu.txt中为你要的东西Top
5 楼dazhu2(【倚天不出,谁与争锋】)回复于 2004-12-02 22:52:14 得分 0
其中文件dazhu.txt中为你要的东西。Top
6 楼NIRVANAIII(问题人物)回复于 2004-12-02 22:58:31 得分 0
好 屠龙 !!!
帅死你!Top
7 楼NIRVANAIII(问题人物)回复于 2004-12-02 23:01:20 得分 0
提交个FAQ给大哥加些信誉Top
8 楼myflyer(凡尘)回复于 2005-03-05 11:07:42 得分 0
private byte[] getLast128(string FileName)
{
FileStream fs = new FileStream(FileName,FileMode.Open,FileAccess.Read);
Stream stream = fs;
stream.Seek(-128,SeekOrigin.End);
const int seekPos = 128;
int rl = 0;
byte[] Info = new byte[seekPos];
rl = stream.Read(Info,0,seekPos);
fs.Close();
stream.Close();
return Info;
}
Top
9 楼myflyer(凡尘)回复于 2005-03-05 11:08:29 得分 0
也是一个不错的方法Top




