-
大小: 36KB文件类型: .rar金币: 1下载: 0 次发布日期: 2021-06-10
- 语言: C#
- 标签:
资源简介
二进制文件的读写,当前时间写入到dat文件中,可以读入读出.C#源代码
用VisualStudio2008创建
http://download.csdn.net/user/gouyue下载
代码片段和文件信息
using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Windows.Forms;
using System.IO;
namespace binary_system
{
public partial class Form1 : Form
{
public Form1()
{
InitializeComponent();
}
private const string FILE_NAME = “Test.dat“;
private void button1_Click(object sender EventArgs e)
{
FileStream fs;
if (File.Exists(FILE_NAME))
{
fs = new FileStream(FILE_NAME FileMode.Truncate);
}
else
{
fs = new FileStream(FILE_NAME FileMode.CreateNew);
}
BinaryWriter w = new BinaryWriter(fs);
w.Write(DateTime.Now.ToString());
w.Write(DateTime.Now.Ticks);
w.Close();
fs.Close();
}
private void button2_Click(object sender EventArgs e)
{
FileStream fs;
fs = new FileStream(FILE_NAME FileMode.OpenOrCreate);
BinaryReader r = new BinaryReader(fs);
MessageBox.Show(r.ReadString() + “\n“ + r.ReadInt64().ToString());
r.Close();
fs.Close();
}
}
}
属性 大小 日期 时间 名称
----------- --------- ---------- ----- ----
I.A.... 8704 2008-12-24 15:12 C#081224-二进制文件的读写\binary system\bin\Debug\binary system.exe
I.A.... 19968 2008-12-24 15:12 C#081224-二进制文件的读写\binary system\bin\Debug\binary system.pdb
I.A.... 14328 2008-12-24 15:13 C#081224-二进制文件的读写\binary system\bin\Debug\binary system.vshost.exe
I.A.... 28 2008-12-24 15:12 C#081224-二进制文件的读写\binary system\bin\Debug\Test.dat
I.A.... 3737 2008-12-24 15:11 C#081224-二进制文件的读写\binary system\binary system.csproj
I.A.... 1360 2008-12-24 15:34 C#081224-二进制文件的读写\binary system\Form1.cs
I.A.... 2580 2008-12-24 15:14 C#081224-二进制文件的读写\binary system\Form1.Designer.cs
I.A.... 5814 2008-12-24 15:14 C#081224-二进制文件的读写\binary system\Form1.resx
I.A.... 558 2008-12-24 15:13 C#081224-二进制文件的读写\binary system\obj\Debug\binary system.csproj.FileListAbsolute.txt
I.A.... 847 2008-12-24 15:11 C#081224-二进制文件的读写\binary system\obj\Debug\binary system.csproj.GenerateResource.Cache
I.A.... 8704 2008-12-24 15:12 C#081224-二进制文件的读写\binary system\obj\Debug\binary system.exe
I.A.... 19968 2008-12-24 15:12 C#081224-二进制文件的读写\binary system\obj\Debug\binary system.pdb
I.A.... 180 2008-12-24 15:11 C#081224-二进制文件的读写\binary system\obj\Debug\binary_system.Form1.resources
I.A.... 180 2008-12-24 15:11 C#081224-二进制文件的读写\binary system\obj\Debug\binary_system.Properties.Resources.resources
I.A.... 494 2008-12-24 15:10 C#081224-二进制文件的读写\binary system\Program.cs
I.A.... 1382 2008-12-24 15:10 C#081224-二进制文件的读写\binary system\Properties\AssemblyInfo.cs
I.A.... 2876 2008-12-24 15:10 C#081224-二进制文件的读写\binary system\Properties\Resources.Designer.cs
I.A.... 5612 2008-12-24 15:10 C#081224-二进制文件的读写\binary system\Properties\Resources.resx
I.A.... 1098 2008-12-24 15:10 C#081224-二进制文件的读写\binary system\Properties\Settings.Designer.cs
I.A.... 249 2008-12-24 15:10 C#081224-二进制文件的读写\binary system\Properties\Settings.settings
I.A.... 929 2008-12-24 15:10 C#081224-二进制文件的读写\binary system.sln
I.A..H. 13312 2008-12-24 15:39 C#081224-二进制文件的读写\binary system.suo
I.A.... 160 2008-12-24 15:38 C#081224-二进制文件的读写\新建 文本文档.txt
I..D... 0 2008-12-24 15:10 C#081224-二进制文件的读写\binary system\obj\Debug\TempPE
I..D... 0 2008-12-24 15:12 C#081224-二进制文件的读写\binary system\bin\Debug
I..D... 0 2008-12-24 15:12 C#081224-二进制文件的读写\binary system\obj\Debug
I..D... 0 2008-12-24 15:10 C#081224-二进制文件的读写\binary system\bin
I..D... 0 2008-12-24 15:10 C#081224-二进制文件的读写\binary system\obj
I..D... 0 2008-12-24 15:10 C#081224-二进制文件的读写\binary system\Properties
I..D... 0 2008-12-24 15:34 C#081224-二进制文件的读写\binary system
............此处省略4个文件信息
评论
共有 条评论