c# FileInfo f = new FileInfo(@"E:\130\19.txt");c new filestreamm fs = f.Create();是什么意思?

C# FileInfo:
You have learned how to perform different tasks on physical files using static File class in the previous section. Here, we will use FileInfo class to perform read/write operation on physical files.
The FileInfo class provides the same functionality as the static File class but you have more control on read/write operations on files by writing code manually for reading or writing bytes from a file.
Important properties and methods of FileInfo:
Gets an instance of the parent directory.
DirectoryName
Gets a string representing the directory's full path.
Gets a value indicating whether a file exists.
Gets the string representing the extension part of the file.
Gets the full path of the directory or file.
IsReadOnly
Gets or sets a value that determines if the current file is read only.
LastAccessTime
Gets or sets the time the current file or directory was last accessed
LastWriteTime
Gets or sets the time when the current file or directory was last written to
Gets the size, in bytes, of the current file.
Gets the name of the file.
AppendText
Creates a StreamWriter that appends text to the file represented by this instance of the FileInfo.
Copies an existing file to a new file, disallowing the overwriting of an existing file.
Creates a file.
CreateText
Creates a StreamWriter that writes a new text file.
Decrypts a file that was encrypted by the current account using the Encrypt method.
Deletes the specified file.
Encrypts a file so that only the account used to encrypt the file can decrypt it.
GetAccessControl
Gets a FileSecurity object that encapsulates the access control list (ACL) entries for a specified file.
Moves a specified file to a new location, providing the option to specify a new file name.
Opens a in the specified FileMode.
Creates a read-only FileStream.
Creates a StreamReader with UTF8 encoding that reads from an existing text file.
Creates a write-only FileStream.
Replaces the contents of a specified file with the file described by the current FileInfo object, deleting the original file, and creating a backup of the replaced file.
Returns a path as string.
The following example shows how to read bytes from a file manually and then convert them to a string using UTF8 encoding:
//Create object of FileInfo for specified path
FileInfo fi = new FileInfo(@"D:\DummyFile.txt");
//Open file for Read\Write
FileStream fs = fi.Open(FileMode.OpenOrCreate, FileAccess.ReadWrite, FileShare.ReadWrite);
//create byte array of same size as FileStream length
byte[] fileBytes = new byte[fs.Length];
//define counter to check how much butes to read. Decrease the counter as you read each byte
int numBytesToRead = (int)fileBytes.L
//Counter to indicate number of bytes already read
int numBytesRead = 0;
//iterate till all the bytes read from FileStream
while (numBytesToRead & 0)
int n = fs.Read(fileBytes, numBytesRead, numBytesToRead);
if (n == 0)
numBytesRead +=
numBytesToRead -=
//Once you read all the bytes from FileStream, you can convert it into string using UTF8 encoding
string filestring = Encoding.UTF8.GetString(fileBytes);
As you have seen in the above code, you have to write lot of code for reading/writing a string from a FileSream. The same read/write operation can be done easily using StreamReader and StreamWriter.
The following example shows how StreamReader makes it easy to read strings from a file:
//Create object of FileInfo for specified path
FileInfo fi = new FileInfo(@"D:\DummyFile.txt");
//Open file for Read\Write
FileStream fs = fi.Open(FileMode.OpenOrCreate, FileAccess.Read , FileShare.Read);
//Create object of StreamReader by passing FileStream object on which it needs to operates on
StreamReader sr = new StreamReader(fs);
//Use ReadToEnd method to read all the content from file
string fileContent = sr.ReadToEnd();
//Close StreamReader object after operation
sr.Close();
fs.Close();
Notice that fi.Open() has three parameters: The first parameter is FileMode for creating and opening a file
the second parameter, FileAccess, is to indicate a R and the third parameter is to share the file for reading with other users while the file is open.
The following example shows how StreamWriter makes it easy to write strings to a File:
//Create object of FileInfo for specified path
FileInfo fi = new FileInfo(@"D:\DummyFile.txt");
//Open file for Read\Write
FileStream fs = fi.Open(FileMode.OpenOrCreate, FileAccess.Write, FileShare.Read );
//Create StreamWriter object to write string to FileSream
StreamWriter sw = new StreamWriter(fs);
sw.WriteLine("Another line from streamwriter");
sw.Close();
Read and Write operations are not possible on the same FileStream object simultaneously. If you are already reading from a file, create a separate FileStream object to write to the same file, as shown below:
//Create FileInfo object for DummyFile.txt
FileInfo fi = new FileInfo(@"D:\DummyFile.txt");
//open DummyFile.txt for read operation
FileStream fsToRead = fi.Open(FileMode.OpenOrCreate, FileAccess.ReadWrite , FileShare.ReadWrite);
//open DummyFile.txt for write operation
FileStream fsToWrite = fi.Open(FileMode.OpenOrCreate, FileAccess.ReadWrite, FileShare.ReadWrite);
//get the StreamReader
StreamReader sr = new StreamReader(fsToRead);
//read all texts using StreamReader object
string fileContent = sr.ReadToEnd();
sr.Close();
//get the StreamWriter
StreamWriter sw = new StreamWriter(fsToWrite);
//write some text using StreamWriter
sw.WriteLine("Another line from streamwriter");
sw.Close();
//close all Stream objects
fsToRead.Close();
fsToWrite.Close();
Thus you can use FileInfo, StreamReader and StreamWriter class to read/write contents from physical file.
Further Reading:
Points to Remember :
Use FileInfo class to perform operations on physical files manually.
Use StreamReader & StreamWriter class with FileInfo for reading or writing string from physical file.
< is optimized for learning web technologies step by step. Examples might be simplified to improve reading and basic understanding. While using this site, you agree to have read and accepted our terms of use and privacy policy.
E-mail list
Subscribe to TutorialsTeacher email list and get latest updates, tips & tricks on C#, .Net, JavaScript, jQuery, AngularJS, Node.js to your inbox.
We respect your privacy.
(C) . All Rights Reserved.C#文件与流(FileStream、StreamWriter 、StreamReader 、File、FileInfo、Directory、DirectoryInfo、Path、Encoding)
C#文件与流(FileStream、StreamWriter 、StreamReader 、File、FileInfo、Directory、DirectoryInfo、Path、Encoding)
发布时间: 4:23:42
编辑:www.fx114.net
本篇文章主要介绍了"C#文件与流(FileStream、StreamWriter 、StreamReader 、File、FileInfo、Directory、DirectoryInfo、Path、Encoding)",主要涉及到C#文件与流(FileStream、StreamWriter 、StreamReader 、File、FileInfo、Directory、DirectoryInfo、Path、Encoding)方面的内容,对于C#文件与流(FileStream、StreamWriter 、StreamReader 、File、FileInfo、Directory、DirectoryInfo、Path、Encoding)感兴趣的同学可以参考一下。
文件与流(FileStream、StreamWriter 、StreamReader 、File、FileInfo、Directory、DirectoryInfo、Path、Encoding)
、定义一个流对象
&fs =&(,.Open,.Read,.Read);
、读取文件
&fs =&&(,.Open);
length = fs.Read([]
buffer,offset,&count);
:这个是字节数组,是用来存放读取的文件的。
:这个是中的相对于起始索引的偏移量,也就是从开始存放的。
:计划从流文件中读取的字节数,countbuffer
返回&#20540;
函数,只要流没有关闭它所指向的文件,那么第一次读取是从第一个字节开始的,第二次读取从第一次读取的最后一个字节的下一个开始,有会自动的将流当前指向的文件的位置往后移动,以后的读取依次类推。
有一个属性,表示它所指向的文件的字节大小,即文件的总长度。
、写入文件
&fs =&&(,.
fs. Write([] buffer,offset,&count);
:这个是字节数组,就是将该字节数组中的数据写入到文件中的。
:这个是中的相对于起始索引的偏移量,也就是从开始读取的。
:从中读取的字节数,写入到文件中,buffer.length - offset
函数,然后只要流没有关闭它所指向的文件,那么第一次写入文件是从文件开头开始写入的,第二次写入是从第一次写入的最后一个字节的下一个开始,有会自动的将流当前指向的文件的位置往后移动,以后的写入依次类推。
fs.Flush();
Write和FlushWriteFlushWrite和Flush
、关闭文件
fs. Close()
Flush()Flush()
、位整数与字节的相互转换
[] buffer =&.GetBytes(&a);
a =&.ToInt32([]
buffer,&startIndex)
、位与字节的相互转换
[] buffer =&.GetBytes(&a);
ToDouble([] buffer,&startIndex)
、字符串与字节的相互转换
[] buffer =&.Default.GetBytes(&a);
&s =&.Default.GetString([]
buffer,&startIndex,&count);
、写文本文件
&sw =&&();
sw.WriteLine();
sw.Write();
sw.Flush();
Write和FlushWriteFlushWrite和Flush
sw. Close()
Flush()Flush()
、读文本文件
&sr =&&(,&.Default);
&str = sr.ReadLine();
&str = sr.ReadToEnd();
、文件拷贝
.Copy(&sourceFileName,&destFileName)
.Copy(&sourceFileName,&destFileName,&overwrite)
、判断文件是否存在
.Exists(&path);
&isExist =&.Exists();
如果path指定的文件还存在,那么就返回,否则返回
、删除文件
.Delete(&path);
、文件移动
.Move(&sourceFileName,&destFileName)
、创建文件
.Create(&path);
、与文件有关的几个时间
.GetCreationTime(&path);
这个函数是获取文件的创建时间,返回。
.GetLastAccessTime(&path);
这个函数是获取最后一次访问文件的时间,返回。
.GetLastWriteTime(&path);
这个函数是获取文件的最后一次的修改时间,返回。
&fi =&&(&fileName);
fi.CopyTo(&destFileName)
fi.CopyTo(&destFileName,&overwrite)
destFileName的。
fi.Delete();
永久删除文件,文件不存在也不会发生异常。
fi.MoveTo(&destFileName)
d:\programmfile\zwj.txt
1、 CreationTime:获取或者设置文件的创建时间。返回&
2、 LastWriteTime:最后一次的修改时间。返回&
3、 LastAcessTime:最后一次的访问时间。返回&
4、 DirectoryName:获取包含该文件的目录的完整路径的字符串:d:\programmfile
5、 FullName:获取包括文件名的完整路径:d:\programmfile\zwj.txt
6、 Name:获取文件名和扩展名:zwj.txt
7、 Extension:获取文件的扩展名:.txt
8、 Exists:指示文件是否存在,存在返回,否则为。
9、 IsReadOnly:获取或者设置当前的文件是否为只读的。是返回,否则为。
10、Length:返回文件的长度,以字节为单位。长整型。
11、Directory:获取包含该文件的目录的DirectoryInfo实例。
.ExecutablePath:获取启动应用程序可执行文件的路径,包括可执行文件的名称:
E: \source\存储过程版\PVPT\MainMenu\bin\Debug\MainMenu.EXE
.StartupPath:获取启动应用程序可执行文件的路径,不包括可执行文件的名称:
E: \source\存储过程版\PVPT\MainMenu\bin\Debug)
1、 创建目录
.CreateDirectory(&path);
按照path所指定的路径去创建目录、子目录,返回一个指向path的对象。这里是创建目录而非文件,不能通过创建一个逻辑盘,只能在现有的逻辑盘下面创建目录。重复创建已经存在的目录是不会发生异常的。任何新创建的目录名不能与该目录同一级目录下的文件名同名,否则就会报错。
2、 删除目录
.Delete(&path);
这个函数是删除目录,这个目录必须为空目录,即里面不能有目录和文件。否则异常。目录不存在也会异常。
.Delete(&path,&recursive);
这个函数是删除目录,当recursive为,那么可以删除非空目录,否则只能删除空目录。目录不存在也会异常。
3、 移动目录
.Move(&sourceDirName,&destDirName)
将原目录的内容全部移到目标目录里面,然后将原目录删除。
4、 判断目录是否存在
.Exists(&path);
存在返回,否则返回。
5、 得到目录的创建时间:.GetCreationTime(&path);
6、 得到目录的最后一次访问时间:.GetLastAccessTime(&path)
7、 得到目录的最后一次修改时间:.GetLastWriteTime(&path)
8、 得到当前的执行程序所在的目录:&.GetCurrentDirectory(&path);
9、&[]&.GetDirectories(&path);
获取指定目录中的子目录名称,只是获取指定目录的下一级,而非下两级或者下三级。返回的是包括目录名在内的完整的路径字符串数组。
10、&[]&.GetFiles(&path);
获取指定目录中的子文件名称,只是获取指定目录的下一级,而非下两级或者下三级。返回的是包括文件名在内的完整的路径字符串数组。
11、&&.GetDirectoryRoot(&path)
获取path执行的路径的根目录,卷信息,比如d:\,path可以是文件或者目录
12、&[]&.GetLogicalDrives();
得到本系统的逻辑盘,以字符串的形式返回。如:d:\
13、&&.GetParent(&path);
14、 得到指定的path的父目录,返回对象,path可以是文件和目录。如果path是根目录,那么就返回。
注意:目录最后不要加\
&di =&&();
1、CreationTime:获取或者设置目录的创建时间。返回&。
2、LastWriteTime:最后一次的修改时间。返回 DateTime。
3、LastAcessTime:最后一次的访问时间。返回 DateTime。
4、Exists:指示目录是否存在,存在返回true,否则为false。
5、FullName:获取目录的完整路径,返回string。
6、Extension:获取目录名的扩展名,返回string。
7、Name:不包含路径的目录名,即文件夹的名字,返回string。
8、Parent:获取父目录,如果当前目录是根目录,就返回null,否则返回DirectoryInfo。
9、Root:获取当前目录的根目录,返回DirectoryInfo。
1、&&di.CreateSubdirectory(&path)
这个是在当前目录的下面创建子目录、子子目录,返回一个新的对象。比如path:a\b\c,a前面不能有\。
2、&di.Delete()
这个表示删除di指定的空目录,如果目录中有内容,那么会引发异常。
&di.Delete(bool)
如果目录不为空,那么表示全部删除,表示不删除。如果目录为空,不论都将直接删除。
3、di.GetDirectories();
返回当前目录的下一级所有子目录。如果没有,返回的数组长度为0.
4、di.GetFiles();
返回当前目录的下一级所有子文件。如果没有,返回的数组长度为0.
.ChangeExtension(&path,&extension);
这个函数是用来更新扩展名的,path为完整的路径,extension是含有签到句点的扩展名。如果path没有扩展名,那么就加上extension,有就直接更新。如果extension为或者空字符串,那么会将path中的扩展名去掉。这个只是对字符串进行变换,对原文件不会有任何的影响。
.GetDirectoryName(&path);
.GetExtension(&path);
返回指定路径的带前导句点的扩展名。如果没有扩展名,就返回长度为0的字符串。如果path为就返回
.GetFileName(&path);
获取包括扩展名在内的文件名,如果是目录,也会当成文件处理。path如果为根目录则返回长度为0的字符串;如果为则返回
.GetFileNameWithoutExtension(&path);
获取不包括扩展名在内的文件名,如果是目录,也会当成文件处理。path如果为根目录则返回长度为0的字符串;如果为则返回
.GetFullPath(&path);
path为相对路径或者绝对路径,返回绝对路径。
.GetPathRoot(&path)
的根目录信息,如果如果path为
去覆盖同名文件,那么被覆盖后,的创建时间不变,最后一次的修改时间变成了的最后一次修改时间。最后一次修改一个文件的时候,如果不保存,那么修改时间还是原来的时间。
一、不得利用本站危害国家安全、泄露国家秘密,不得侵犯国家社会集体的和公民的合法权益,不得利用本站制作、复制和传播不法有害信息!
二、互相尊重,对自己的言论和行为负责。
本文标题:
本页链接:C#基础-FileStream_asp.net开发_ThinkSAAS
C#基础-FileStream
C#基础-FileStream
内容来源: 网络
一、FileStream的基础知识&#13;
  属性:  
CanRead 判断当前流是否支持读取,返回bool值,True表示可以读取  
CanWrite 判断当前流是否支持写入,返回bool值,True表示可以写入&#13;
  方法:  
Read() 从流中读取数据,返回字节数组  
Write() 将字节块(字节数组)写入该流  
Seek() 设置文件读取或写入的起始位置  
Flush() 清除该流缓冲区,使得所有缓冲的数据都被写入到文件中  
Close() 关闭当前流并释放与之相关联的所有系统资源&#13;
  文件的访问方式:(FileAccess)  
FileAccess.Read(对文件读访问)  
FileAccess.Write(对文件进行写操作)  
FileAccess.ReadWrite(对文件读或写操作)&#13;
  文件打开模式:(FileMode)包括6个枚举  
FileMode.Append 打开现有文件准备向文件追加数据,只能同FileAccess.Write一起使用  
FileMode.Create 指示操作系统应创建新文件,如果文件已经存在,它将被覆盖  
FileMode.CreateNew 指示操作系统应创建新文件,如果文件已经存在,将引发异常 
  FileMode.Open 指示操作系统应打开现有文件,打开的能力取决于FileAccess所指定的值  
FileMode.OpenOrCreate 指示操作系统应打开文件,如果文件不存在则创建新文件  
FileMode.Truncate 指示操作系统应打开现有文件,并且清空文件内容&#13;
  文件共享方式:(FileShare)  
FileShare方式是为了避免几个程序同时访问同一个文件会造成异常的情况。  文件共享方式包括四个: 
 FileShare.None 谢绝共享当前文件 
 FileShare.Read 充许别的程序读取当前文件 
 FileShare.Write 充许别的程序写当前文件 
 FileShare.ReadWrite 充许别的程序读写当前文&#13;
二、FileStream的异步操作&#13;
1 using S&#13;
2 using System.Collections.G&#13;
3 using ponentM&#13;
4 using System.D&#13;
5 using System.D&#13;
6 using System.L&#13;
7 using System.T&#13;
8 using System.Threading.T&#13;
9 using System.Windows.F&#13;
10 using System.IO;&#13;
11 using System.T&#13;
13 namespace StreamWin&#13;
public partial class Form1 : Form&#13;
public Form1()&#13;
InitializeComponent();&#13;
private void button1_Click(object sender, EventArgs e)&#13;
string filePaths = @"E:TestTestlocala.txt";&#13;
string fileName ="a.txt" ;&#13;
System.IO.FileInfo f = new FileInfo(@"E:TestTestservera.txt");&#13;
int fileLength = Convert.ToInt32(f.Length.ToString());&#13;
ThreadPool.SetMaxThreads(100, 100);&#13;
using (System.IO.FileStream stream = new System.IO.FileStream(filePaths, FileMode.Create,FileAccess.Write, FileShare.Write, 1024, true))&#13;
for (int i = 0; i & fileL i +=100 * 1024)&#13;
int length = (int)Math.Min(100 * 1024, fileLength - i);&#13;
var bytes = GetFile(fileName, i, length);&#13;
stream.BeginWrite(bytes, 0, length, new AsyncCallback(Callback), stream);&#13;
stream.Flush();&#13;
public static byte[] GetFile(string name, int start, int length)&#13;
string filepath = @"E:TestTestservera.txt";&#13;
using (System.IO.FileStream fs = new System.IO.FileStream(filepath, System.IO.FileMode.Open, System.IO.FileAccess.Read, FileShare.ReadWrite,1024,true))&#13;
byte[] buffer = new byte[length];&#13;
fs.Position =&#13;
fs.BeginRead(buffer, 0, length,new AsyncCallback(Completed),fs);&#13;
return&#13;
static void Completed(IAsyncResult result)&#13;
FileStream fs = (FileStream)result.AsyncS&#13;
fs.EndRead(result);&#13;
fs.Close();&#13;
public static void Callback(IAsyncResult result)&#13;
FileStream stream = (FileStream)result.AsyncS&#13;
stream.EndWrite(result);&#13;
stream.Close();&#13;
内容来源:
PHP开发框架
开发工具/编程工具
服务器环境
ThinkSAAS商业授权:
ThinkSAAS为用户提供有偿个性定制开发服务
ThinkSAAS将为商业授权用户提供二次开发指导和技术支持
让ThinkSAAS更好,把建议拿来。
开发客服微信使用 FileStream 类对文件系统上的文件进行读取、写入、打开和关闭操作,并对其他与文件相关的操作系统句柄进行操作,如管道、标准输入和标准输出。读写操作可以指定为同步或异步操作。FileStream 对输入输出进行缓冲,从而提高性能。&先看代码,后面讲解:&using&Susing&System.Collections.Gusing&ponentMusing&System.Dusing&System.Dusing&System.Lusing&System.Tusing&System.Windows.Fusing&System.IO;//注意,必不可少namespace&WasteIndustry&{&&&&public&partial&class&Form3&:&Form&{&&&&&&&&public&Form3()&{&&&&&&&&&&&&InitializeComponent();&/*&*&C#&Program&*&Author:神舟龙&*&Email:&&*/&&&&&&&&}&&&&&&&&private&void&Form3_Load(object&sender,&EventArgs&e)&{&&&&&&&&&&&&//创建一个文本文件,并实例化一个文件流&&&&&&&&&&&&FileStream&MyFileStream1&=&new&FileStream(@"D:\Test.text",FileMode.Create);&&&&&&&&&&&&&&&&&&&&&&&&FileInfo&MyFiles&=&new&FileInfo(@"D;\Test.text");&&&&&&&&&&&&//实例化一个只读文件流&&&&&&&&&&&&FileStream&MyFileStream2&=&MyFiles.OpenRead();&&&&&&&&&&&&//设置文件流为只写权限&&&&&&&&&&&&MyFileStream2&=&MyFiles.OpenWrite();&&&&&&&&&&&&//设置文件流的打开方式为追加模式,只读权限,不共享&&&&&&&&&&&&MyFileStream2&=&MyFiles.Open(FileMode.Append,FileAccess.Read,FileShare.None);&&&&&&&&&&&&//创建文件&&&&&&&&&&&&MyFileStream2&=&MyFiles.Create();&&&&&&&&&&&&//从文件中读取字节&&&&&&&&&&&&int&MyBytes&=&MyFileStream1.ReadByte();&&&&&&&&&&&&//定义数组长度&&&&&&&&&&&&int&NumberOFBytes&=&20;&&&&&&&&&&&&//byte类型数组&&&&&&&&&&&&byte[]&MyByteArray&=&new&byte[NumberOFBytes];&&&&&&&&&&&&//从文件中读取20个字节放入数组中&&&&&&&&&&&&int&BytesRead&=&MyFileStream1.Read(MyByteArray,0,NumberOFBytes);&&&&&&&&&&&&//定义一个字节&&&&&&&&&&&&byte&MyWriteByte&=&100;&&&&&&&&&&&&//向文件中写入一个字节&&&&&&&&&&&&MyFileStream1.WriteByte(MyWriteByte);&&&&&&&&&&&&//定义数组长度&&&&&&&&&&&&int&NumberOfBytesToWrite&=&256;&&&&&&&&&&&&//定义byte类型数组&&&&&&&&&&&&byte[]&MyWriteByteArray=new&Byte[NumberOfBytesToWrite];&&&&&&&&&&&&//循环向byte类型的数组中插入byte值&&&&&&&&&&&&for&(int&i&=&0;&i&&&256;&i++)&{&&&&&&&&&&&&&&&&MyWriteByteArray[i]=(byte)i;&&&&&&&&&&&&&&&&i++;&&&&&&&&&&&&}&&&&&&&&&&&&//向流中写入数组内容&&&&&&&&&&&&MyFileStream1.Write(MyWriteByteArray,0,NumberOfBytesToWrite);&&&&&&&&&&&&//关闭流&&&&&&&&&&&&MyFileStream1.Close();&&&&&&&&&&&&//关闭流&&&&&&&&&&&&MyFileStream2.Close();&&&&&&&&}&&&&}}&MyFileStream1对象,使用指定路径和创建模式实例化,创建模式FileMode是一个枚举类型,它还包括:&
可以打开现有的文件并查找的文件尾部,FileMode.Append只能与FileAcces.Write(写权限)一起使用
创建新文件,如果文件存在则覆盖,没有则新建
创建新文件,有的话,出现异常
打开现有的文件,如果有打开,不存在文件就会引发异常
如果存在文件则打开,不存在则创建
如果存在文件则打开,不存在则创建
&MyFileStream2对象,用FileInfo实例化,FileInfo方法有open,openreade,opentext,create,createtext。文件流的读取(read)与写入(write);read&&&&&&&&&&&&//定义数组长度&&&&&&&&&&&&int&NumberOFBytes&=&20;&&&&&&&&&&&&//byte类型数组&&&&&&&&&&&&byte[]&MyByteArray&=&new&byte[NumberOFBytes];&&&&&&&&&&&&//从文件中读取20个字节放入数组中&&&&&&&&&&&&int&BytesRead&=&MyFileStream1.Read(MyByteArray,0,NumberOFBytes);定义一个byte类型的数组,设置数组的长度,read方法就是在文件中从0开始读取,读取20个字节数,然后替换到数组中&&//定义数组长度&&&&&&&&&&&&int&NumberOfBytesToWrite&=&256;&&&&&&&&&&&&//定义byte类型数组&&&&&&&&&&&&byte[]&MyWriteByteArray=new&Byte[NumberOfBytesToWrite];&&&&&&&&&&&&//循环向byte类型的数组中插入byte值&&&&&&&&&&&&for&(int&i&=&0;&i&&&256;&i++)&{&&&&&&&&&&&&&&&&MyWriteByteArray[i]=(byte)i;&&&&&&&&&&&&&&&&i++;&&&&&&&&&&&&}&&&&&&&&&&&&//向流中写入数组内容&&&&&&&&&&&&MyFileStream1.Write(MyWriteByteArray,0,NumberOfBytesToWrite);&定义一个byte类型的数组,设置数组的长度,并通过循环想byte数组中写入字节,通过write方法把数组中的值从0位置开始向流中写入内容;&&(园内低手,口下留情,欢迎指正!)&&
阅读(...) 评论()

我要回帖

更多关于 fileinfo filestream 的文章

 

随机推荐