C#创建Windows窗体应用程序实例12【文件管理】
来源:http://www.tudoupe.com时间:2022-05-04
你不打算做一个工程。你不会去完成它。你不会写代码。请从底部读到底部。
示例1: C# 构建窗口窗体应用程序
C# Windows 窗体应用程序的例2
1. 知识点
第1步:打开文件并阅读文本
StreamReader rd1=new StreamReader(@”c:a.txt”);
while((line=rd1.ReadLine())!=null) { Console.WriteLine(line); }
rd1.Close();
第2步:打开文件并阅读文本
using(StreamReader d1=new StreamReader(@”c:a.txt”)) {
string line;
while((line=rd1.ReadLine())!=null) {
Console.WriteLine(line);
}
}
第1步:打开文件并输入文本
StreamWriter sw=new StreamWriter(@”c:a.txt”);
sw.WriteLine(“Suzhou”);
sw.WriteLine(“125.3”); sw.Close();
第2步:打开文件并写入文本
using(StreamWriter sw=new StreamWriter(@”c:a.txt”)) {
sw.WriteLine(“Suzhou”);
sw.WriteLine(“125.3”);
}
创建文件Stream 对象( 打开文件)
FileStream 方法 1 fs= new FileStream (@ “ c: a. org ) “ FileMode ” “ 创建 ”
方法2: 创建文件流 fs = File.Create (@ c: a. org) txt ” ;
文件定位
fs.Seek.Begin; fs.Seek.Begin; fs.Seek.Begin; fs.
fs.Seek. 现在的位置是现在
fs.Seek.End;文件的结尾;
写入/读取数据
byte[] info=new UTF8Encoding(true).GetBytes(“A”);
我不知道你是什么意思, Fs. write( info, 0, info. info. Length; // 写入字节数据)
byte[] b=new byte[1024];
我不知道你指的是什么 Fs. Read(b,0,b.Length;// 读字节数据)
关闭流
fs.Close();
或利用声明
2. 样式设计
在工具中,选择以下控件:
3. 代码实现
4. 执行效果


相关新闻
- 2022-08-04 WPF的由来
- 2022-08-04 Win11勒索软件防护怎么打开?Win11安
- 2022-08-04 Windows系统jdk的配置
- 2022-08-04 Windows10 OneNote怎么重新登录?如何重
- 2022-08-04 超好用的 Windows 效率工具推荐
- 2022-08-04 Windows如何在CMD或PowerShell中配置代理
- 2022-08-04 powershell和cmd对比
- 2022-08-04 【QT】Windows下QT下载安装
- 2022-08-04 windows下 C++ 实现类属性的get和set方
- 2022-08-04 Win11快速助手在哪里?Win11打开快速
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|








