问题描述
PB8代码:blobbb=blob(space(4))blobedit(b,1,987)//987是数据intli_FileNum;Filedelete("d:a.txt");li_FileNum=FileOpen("d:a.txt",&StreamMode!,Write!,LockWrite!,Append!)FileWrite(li_FileNum,b)messagebox("",string(long(b)))//PB中读取出来是987FileClose(li_FileNum);
C#代码publicbyte[]GetFileBytes(stringfileName,Encodingencoding=null){byte[]data=null;try{using(FileStreamfilestream=newFileStream(fileName,FileMode.Open,FileAccess.Read)){using(BinaryReaderbr=newBinaryReader(filestream,encoding==null?ASCIIEncoding.Default:encoding)){data=newbyte[filestream.Length];br.Read(data,0,data.Length);}}}catch(FileNotFoundException){thrownewException("文件未找到!");}returndata;}privatevoidsimpleButton4_Click(objectsender,EventArgse){//此处读取出来的字节数据中b[0]=219,b[1]=3,b[2]=0,b[3]=0,如何读取正确的数据:987varb=GetFileBytes(@"d:a.txt");vars=System.Text.ASCIIEncoding.Default.GetString(b);}
解决方案
解决方案二:
3*256+219=?
解决方案三:
File.ReadAllText不行么?你这样读都不知道用的什么Encoding去读取的byte,然后后面又用ASCII来解
解决方案四:
Console.WriteLine((3<<8)+219);
这样至少凑出来是987