c++ createfile函数 createfile函数

2024-08-03 12:52:33 精选百科 >
导读 今天周周为大家解答以上的问题。c++ createfile函数,createfile函数相信很多小伙伴还不知道,现在让我们一起来看看吧!1、你找的是c++里的...

今天周周为大家解答以上的问题。c++ 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()); } }}。

本文就为大家分享到这里,希望小伙伴们会喜欢。

郑重声明:本文版权归原作者所有,转载文章仅为传播更多信息之目的,如作者信息标记有误,请第一时间联系我们修改或删除,多谢。

热门文章

热点推荐

精选文章