zoukankan
html css js c++ java
读取和写入二进制数据
在.NET平台,BinaryWriter 和
BinaryReader
类用于读取和写入二进制数据。
Code
1
using
System;
2
using
System.IO;
3
class
MyStream
4
{
5
private
const
string
FILE_NAME
=
"
Test.data
"
;
//
定义文件名
6
public
static
void
Main(String[] args)
7
{
8
//
检查是否文件已经存在
9
if
(File.Exists(FILE_NAME))
10
{
11
Console.WriteLine(
"
{0} already exists!
"
, FILE_NAME);
12
return
;
13
}
14
FileStream fs
=
new
FileStream(FILE_NAME, FileMode.CreateNew);
15
//
建立读写流
16
BinaryWriter w
=
new
BinaryWriter(fs);
17
//
写入测试数据
18
for
(
int
i
=
0
; i
<
11
; i
++
)
19
{
20
w.Write( (
int
) i);
21
}
22
w.Close();
23
fs.Close();
24
//
建立读取类.
25
fs
=
new
FileStream(FILE_NAME, FileMode.Open, FileAccess.Read);
26
BinaryReader r
=
new
BinaryReader(fs);
27
28
29
//
读取测试数据
30
31
for
(
int
i
=
0
; i
<
11
; i
++
)
32
{
33
Console.WriteLine(r.ReadInt32());
34
}
35
r.Close();
36
fs.Close();
37
}
38
}
39
40
上面的代码示例演示如何向新的空文件流 (
Test.data
) 写入数据及从中读取数据。
查看全文
相关阅读:
Qt 学习之路 :自定义只读模型
Qt 学习之路:QSortFilterProxyModel
Qt 学习之路 :可视化显示数据库数据
Qt 学习之路 :访问网络(4)
Qt 学习之路:QFileSystemModel
高级Bash脚本编程指南
CGI
shell学习
【shell】while read line 与for循环的区别
管道技巧-while read line
原文地址:https://www.cnblogs.com/CCJVL/p/1355382.html
最新文章
Android图像处理之熔铸特效
Java图像渐变
Android学习笔记之图像颜色处理(ColorMatrix)
Android 学习笔记之Bitmap位图虽触摸点移动
Android 学习笔记之Bitmap位图的旋转
Spring 从零開始-05
敏捷大拇指帅哥美女大型派对 [北京][免费]
4Sum -- LeetCode
操作系统栈溢出检測之ucosII篇
pssh,pscp,pslurp使用实践
热门文章
哈哈,你造原来程序猿这么多长处嘛
URAL 1180. Stone Game (博弈 + 规律)
UVA 322 ships (POJ 1138)
组件接口(API)设计指南[4]-通知(Notifications)
安装windows7导致Ubuntu启动项消失的问题的解决
Qt 学习之路 :Qt 线程相关类
Qt 学习之路:线程和事件循环
Qt 学习之路 :线程简介
win32下进程间通信——共享内存
Qt 学习之路 :进程间通信
Copyright © 2011-2022 走看看