您当前的位置: 首页 > 快讯 >

createfile函数的设备名参数如何设置-世界今日报

2023-03-08 21:57:38 来源:互联网


【资料图】

有关createfile函数的设备名参数如何设置这方面的知识,估计很多人不是太了解,今天就给大家详细的介绍一下关于createfile函数的设备名参数如何设置的相关内容。

1、你找的是c++里的创建文件的函数,在c#里应该是用下面的--------------------------------------------------------------------------------------File 类提供用于创建、复制、删除、移动和打开文件的静态方法,并协助创建 FileStream 对象。

2、继承层次结构System.Object ***.IO.File命名空间: ***.IO程序集: mscorlib(在 mscorlib.dll 中)语法C#public static class FileFile 类型公开以下成员。

3、公共方法静态成员 Create(String) 在指定路径中创建或覆盖文件。

4、公共方法静态成员 Create(String, Int32) 创建或覆盖指定的文件。

5、公共方法静态成员 Create(String, Int32, FileOptions) 创建或覆盖指定的文件,并指定缓冲区大小和一个描述如何创建或覆盖该文件的 FileOptions 值。

6、公共方法静态成员 Create(String, Int32, FileOptions, FileSecurity) 创建或覆盖具有指定的缓冲区大小、文件选项和文件安全性的指定文件。

7、下面的示例在指定路径中创建一个文件,将一些信息写入该文件,再从文件中读取。

8、using System;using ***.IO;using System.Text;class Test{ public static void Main() { string path = @"c:empMyTest.txt"; try { // Delete the file if it exists. if (File.Exists(path)) { // Note that no lock is put on the // file and the possibility exists // that another process could do // something with it between // the calls to Exists and Delete. File.Delete(path); } // Create the file. using (FileStream fs = File.Create(path)) { Byte[] info = new UTF8Encoding(true).GetBytes("This is some text in the file."); // Add some information to the file. fs.Write(info, 0, info.Length); } // Open the stream and read it back. using (StreamReader sr = File.OpenText(path)) { string s = ""; while ((s = sr.ReadLine()) != null) { Console.WriteLine(s); } } } catch (Exception Ex) { Console.WriteLine(Ex.ToString()); } }}。

上一篇:

下一篇:

x
精彩推送