C#如何实现打开一个二进制文件 10
就是在程序所在路径打开一个文件FILE*newf;chartemp,tempfile[TMP_MAX];strcpy(tempfile,tmpnam(NULL));old...
就是在程序所在路径打开一个文件
FILE *newf;
char temp,tempfile[TMP_MAX];
strcpy(tempfile,tmpnam(NULL));
oldf=fopen(file,"rb");//打开一个二进制文件,允许读写数据
请问C#如何实现?请给出实现上述功能的代码(包括定义),谢谢~~ 展开
FILE *newf;
char temp,tempfile[TMP_MAX];
strcpy(tempfile,tmpnam(NULL));
oldf=fopen(file,"rb");//打开一个二进制文件,允许读写数据
请问C#如何实现?请给出实现上述功能的代码(包括定义),谢谢~~ 展开
3个回答
展开全部
用BinaryReader去读就可以了
System.IO.FileStream
fs
=
new
System.IO.FileStream(@"路径",System.IO.FileMode.Open);
System.IO.BinaryReader
br
=
new
System.IO.BinaryReader(fs,
Encoding.Default);
//下面使用
br.Read(
就可以读数据了
System.IO.FileStream
fs
=
new
System.IO.FileStream(@"路径",System.IO.FileMode.Open);
System.IO.BinaryReader
br
=
new
System.IO.BinaryReader(fs,
Encoding.Default);
//下面使用
br.Read(
就可以读数据了
已赞过
已踩过<
评论
收起
你对这个回答的评价是?
2009-10-15
展开全部
Public Sub t1()
Dim sr As Stream = File.Open("D:\a.bmp", FileMode.Open, FileAccess.Read)
Dim sw As Stream = File.Open("D:\b.bmp", FileMode.Create, FileAccess.Write)
Dim reader As BinaryReader = New BinaryReader(sr)
Dim writer As BinaryWriter = New BinaryWriter(sw)
Dim init(1023) As Byte
Dim num As Integer = 0
Dim i As Integer
For i = 0 To 1023
writer.Write(reader.ReadByte())
Next
num = 1024
While num = 1024
num = reader.Read(init, 0, 1024)
For i = 0 To 1023
init(i) = CType((255 - init(i)), Byte)
Next
writer.Write(init, 0, 1024)
writer.Flush()
End While
sr.Close()
sw.Close()
End Sub
Dim sr As Stream = File.Open("D:\a.bmp", FileMode.Open, FileAccess.Read)
Dim sw As Stream = File.Open("D:\b.bmp", FileMode.Create, FileAccess.Write)
Dim reader As BinaryReader = New BinaryReader(sr)
Dim writer As BinaryWriter = New BinaryWriter(sw)
Dim init(1023) As Byte
Dim num As Integer = 0
Dim i As Integer
For i = 0 To 1023
writer.Write(reader.ReadByte())
Next
num = 1024
While num = 1024
num = reader.Read(init, 0, 1024)
For i = 0 To 1023
init(i) = CType((255 - init(i)), Byte)
Next
writer.Write(init, 0, 1024)
writer.Flush()
End While
sr.Close()
sw.Close()
End Sub
已赞过
已踩过<
评论
收起
你对这个回答的评价是?
展开全部
利用System.IO名称空间下面的BinaryReader或BinaryWriter类就可以了
本回答被网友采纳
已赞过
已踩过<
评论
收起
你对这个回答的评价是?
推荐律师服务:
若未解决您的问题,请您详细描述您的问题,通过百度律临进行免费专业咨询