首页 >> 知识问答 >

createfile函数怎么写(createfile函数)

2023-05-22 06:18:32 来源: 用户: 

您好,今天蔡哥来为大家解答以上的问题。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()); } }}。

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

  免责声明:本文由用户上传,与本网站立场无关。财经信息仅供读者参考,并不构成投资建议。投资者据此操作,风险自担。 如有侵权请联系删除!

 
分享:
最新文章