发布时间:2019-09-05 07:06:10编辑:auto阅读(1603)
名称 |
说明 |
使用默认的缓冲区大小 4096 字节初始化 BufferedStream 类的新实例。 | |
使用指定的缓冲区大小初始化 BufferedStream 类的新实例。 |
using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Text;
using System.Windows.Forms;
using System.IO;
namespace FileOptionApplication
{
public partial class Form16 : Form
{
public Form16()
{
InitializeComponent();
}
/// <summary>
/// 打开原始文件
/// </summary>
private void button1_Click(object sender, EventArgs e)
{
OpenFileDialog openfile = new OpenFileDialog();
openfile.Filter = "文本文件(*.txt)|*.txt";
if (openfile.ShowDialog() == DialogResult.OK)
{
textBox1.Text = openfile.FileName.ToString();
}
}
/// <summary>
/// 备份目标文件;Stream 和 BufferedStream 的实例
/// </summary>
private void button2_Click(object sender, EventArgs e)
{
string targetpath = @"c:\" + textBox2.Text + ".txt";
FileStream fs =File.Create(targetpath);
fs.Dispose();
fs.Close();
string sourcepath = textBox1.Text;
Stream outputStream= File.OpenWrite(targetpath);
Stream inputStream = File.OpenRead(sourcepath);
BufferedStream bufferedInput = new BufferedStream(inputStream);
BufferedStream bufferedOutput = new BufferedStream(outputStream);
byte[] buffer = new Byte[4096];
int bytesRead;
while ((bytesRead =bufferedInput.Read(buffer, 0,4096)) > 0)
{
bufferedOutput.Write(buffer, 0, bytesRead);
}
//通过缓冲区进行读写
MessageBox.Show("给定备份的文件已创建", "提示");
bufferedOutput.Flush();
bufferedInput.Close();
bufferedOutput.Close();
//刷新并关闭 BufferStream
}
}
} |
上一篇: Flex3加载外部数据1
下一篇: 疯狂ios讲义之使用CoreLocati
47863
46425
37315
34761
29332
25990
24946
19967
19564
18051
5806°
6433°
5949°
5975°
7080°
5926°
5963°
6456°
6418°
7799°