当前位置: 首页>>代码示例>>C#>>正文


C# FileInfo.CreateText方法代码示例

本文整理汇总了C#中FileInfo.CreateText方法的典型用法代码示例。如果您正苦于以下问题:C# FileInfo.CreateText方法的具体用法?C# FileInfo.CreateText怎么用?C# FileInfo.CreateText使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在FileInfo的用法示例。


在下文中一共展示了FileInfo.CreateText方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。

示例1: CreateFileWithString

    /**
    * path:文件创建目录
    *  info:写入的内容
    */
    public static void CreateFileWithString(string path, string info)
    {
        //文件流信息
        StreamWriter sw;
        FileInfo t = new FileInfo(path);

        CreateDirectory(System.IO.Path.GetDirectoryName(path));

        if(!t.Exists)
        {
            //如果此文件不存在则创建
            sw = t.CreateText();
        }
        else
        {
            //如果此文件存在则删除
            File.Delete(path);
            sw = t.CreateText();
        }
        //以行的形式写入信息
        sw.Write(info);
        //关闭流
        sw.Close();
        //销毁流
        sw.Dispose();
    }
开发者ID:nottvlike,项目名称:OpenWorldGame,代码行数:30,代码来源:FileManager.cs

示例2: OnApplicationQuit

    void OnApplicationQuit()
    {
        string playerId = Extensions.Player.playerId;
        #if UNITY_EDITOR

        if(Extensions.Player.controlType==PlayerBeheaver.ControlType.mono){

            FileInfo f = new FileInfo( Application.persistentDataPath + "\\" + playerId+".txt");
            StreamWriter w;
            if(!f.Exists)
            {
                w = f.CreateText();
            }
            else
            {
                f.Delete();
                w = f.CreateText();
            }
            //w.WriteLine(loadMessage);
            w.WriteLine (playerId);
            foreach(StageStatistic s in statistics){
                w.WriteLine(s.gameObject.name+", "+s.counter.ToString());
            }

            w.Close();
            Debug.Log("saves");
        }
        #endif
    }
开发者ID:Cabris,项目名称:unity_lab,代码行数:29,代码来源:StagesStatistic.cs

示例3: CreateXML

 void CreateXML(string data)
 {
     StreamWriter writer;
     FileInfo t = new FileInfo(fileLocation + "\\" + fileName);
     if (!t.Exists)
     {
         writer = t.CreateText();
     }
     else
     {
         writer = t.CreateText();
     }
     writer.Write(data);
     writer.Close();
 }
开发者ID:sean-h,项目名称:spacegame,代码行数:15,代码来源:ConfigFileManager.cs

示例4: SaveJson

    public void SaveJson(string txt)
    {
        string path=Application.dataPath+"//Resource//";

        path = "./Assets/Resources/TXT/Edit_NewGesture.txt";

        string file = path;

        StreamWriter sw;

        FileInfo t = new FileInfo(file);

        if(!t.Exists)
        {
           // Debug.LogError("SaveJson1: " + path);

            sw = t.CreateText();
        }
        else
        {
            //Debug.LogError("SaveJson2: " + path);

            sw = t.AppendText();
        }
        sw.WriteLine(txt);
        sw.Close();
        sw.Dispose();
    }
开发者ID:aminebenali,项目名称:dancing-cell-code,代码行数:28,代码来源:GestureTest.cs

示例5: CreateXML

 /// <summary>
 /// 创建XML文件
 /// </summary>
 private static void CreateXML(string filePath, string dataStr)
 {
     Logger.INFO("Save: " + filePath);
     StreamWriter writer;
     FileInfo t = new FileInfo(filePath);
     if (!t.Exists)
         writer = t.CreateText();
     else
     {
         t.Delete();
         writer = t.CreateText();
     }
     writer.Write(dataStr);
     writer.Close();
     writer.Dispose();
 }
开发者ID:JingChen1988,项目名称:Bubble,代码行数:19,代码来源:Persistence.cs

示例6: fnCreateFile

	void fnCreateFile()
	{

		StreamWriter t_sStreamWriter; // 文件流信息
		FileInfo t_fFileInfo = new FileInfo(Application.dataPath + "//" + "儀式的條件.txt");
		if (!t_fFileInfo.Exists)
		{
			t_sStreamWriter = t_fFileInfo.CreateText();

			// 如果此文件不存在则创建
		}
		else
		{
			t_sStreamWriter = t_fFileInfo.AppendText(); // 如果此文件存在则打开

		}
		for(int i=0 ; i < 6 ; i++)
		{
			t_sStreamWriter.Write("第");
			t_sStreamWriter.Write((i+1).ToString());
			t_sStreamWriter.WriteLine("組");
			t_sStreamWriter.WriteLine(@"------------------------------------------------------");
			for(int j = 0 ; j < 3 ; j++)
			{
				t_sStreamWriter.WriteLine(Objlist[j+i*3]);

			}
			t_sStreamWriter.Write("拿取");
			t_sStreamWriter.WriteLine(Targetlist[i]);
			t_sStreamWriter.WriteLine(@"------------------------------------------------------");
		}
		// 以行的形式写入信息 
		t_sStreamWriter.Close(); //关闭流
		t_sStreamWriter.Dispose(); // 销毁流
	}
开发者ID:gmfnasg,项目名称:GGJ2016TaipeiTeamK,代码行数:35,代码来源:TestBehaviourScript.cs

示例7: CreateFile

    //
    void CreateFile(string sPath, string sName, string sInfo)
    {
        // 文件流信息
        StreamWriter sw;
        FileInfo t = new FileInfo (sPath + "//" + name);

        if (!t.Exists)
        {
            // 如果此文件不存在創建
            sw = t.CreateText ();
        }
        else
        {
            // 如果此文件存在,則打開該文件
            sw = t.AppendText();
        }

        //以行的形式寫入信息
        sw.WriteLine (sInfo);

        // 關閉流
        sw.Close ();

        // 銷毀流
        sw.Dispose ();
    }
开发者ID:ChuHaiLing,项目名称:UGUI_pro,代码行数:27,代码来源:SaveTest.cs

示例8: bconfirm_Click

    protected void bconfirm_Click(object sender, EventArgs e)
    {
        if (Session["Directory"] != null)
        {
            this.div1.InnerHtml = this.TextBoxEdit.Text;
            textSrc = Request.QueryString["src"];

            srcPath = Server.MapPath("~/Text/") + Session["Course"] + "/" + Session["Directory"].ToString() + "/" + textSrc + ".txt";

            FileInfo myFile = new FileInfo(srcPath);
            StreamWriter sw = myFile.CreateText();
            sw.Write(this.TextBoxEdit.Text, System.Text.Encoding.GetEncoding("UTF-8"));
            sw.Close();

            if (ViewState["UrlReferrer"] != null)
            {
                Response.Redirect(ViewState["UrlReferrer"].ToString());
            }
        }
        else
        {
            Response.Redirect("../Default.aspx");
            return;
        }
    }
开发者ID:dalinhuang,项目名称:my-project-step,代码行数:25,代码来源:EditPage.aspx.cs

示例9: OnLoad

 public void OnLoad()
 {
     FileInfo fileInfo = new FileInfo(@"Modules\Kernel\FileWritingModule\WrittenFile");
     StreamWriter text = fileInfo.CreateText();
     text.WriteLine("PermissionSet allows me to write files!");
     text.Close();
 }
开发者ID:NomadPL,项目名称:Nomad,代码行数:7,代码来源:FileWritingModule.cs

示例10: WriteXML

    public static void WriteXML(FileInfo fileinfo, List<List<string>> parsedXML)
    {
        StreamWriter writer;

        if (!fileinfo.Exists)
        {
            writer = fileinfo.CreateText();
        }
        else
        {
            fileinfo.Delete();
            writer = fileinfo.CreateText();
        }

        //write data to file.
        {
            writer.Write("<Resources>\n");
            for (int i=0;i<parsedXML.Count;i++)
            {
                writer.Write("\t<Key  Value=\"" + parsedXML[i][1] + "\"  en=\"" + parsedXML[i][2] + "\"  zh-CN=\"" + parsedXML[i][3] + "\">" + parsedXML[i][0] + "</Key>\n");
            }
            writer.Write("</Resources>");
        }

        writer.Close();
        Debug.Log("File exported.");
    }
开发者ID:wuxin0602,项目名称:Nothing,代码行数:27,代码来源:FileIO.cs

示例11: WriteLogFile

		private void WriteLogFile (string message, string logFile)
			{
			string fname = logFile;
			if (string.IsNullOrEmpty (fname))
				return;
			FileInfo info = new FileInfo (fname);
			StreamWriter sw;

			// Open the file
			try
				{
				if (info.Exists)
					sw = info.AppendText ();
				else
					sw = info.CreateText ();
				}
			catch
				{
				// We weren't able to open the file for some reason.
				// We can't write to the log file; so give up.
				return;
				}

			using (sw)
				{
				sw.Write (message);
				sw.Flush ();
				}
			}
开发者ID:oznetmaster,项目名称:SSMonoDiagnosticsLibrary,代码行数:29,代码来源:DefaultTraceListener.cs

示例12: SaveXML

	private static void SaveXML(string filename, string xml) 
	{ 
		StreamWriter writer; 
		FileInfo t = new FileInfo(Application.dataPath + "/Resources/Xml/" + filename); 
		if(!t.Exists) 
		{ 
			writer = t.CreateText(); 
		} 
		else 
		{ 
			//t.Delete(); 
			writer = t.CreateText(); 
		} 
		writer.Write(xml); 
		writer.Close();
	} 
开发者ID:azanium,项目名称:Klumbi-Unity,代码行数:16,代码来源:XmlManager.cs

示例13: CreateXML

 //------------------------------------------
 void CreateXML()
 {
     StreamWriter writer;
       FileInfo t = new FileInfo(_FileLocation+"\\"+ _FileName);
       if(!t.Exists)
       {
      writer = t.CreateText();
       }
       else
       {
      t.Delete();
      writer = t.CreateText();
       }
       writer.Write(_data);
       writer.Close();
       Debug.Log("File written.");
 }
开发者ID:gviaud,项目名称:OS-unity-5,代码行数:18,代码来源:SaveToolSet.cs

示例14: CreateXML

 // Finally our save and load methods for the file itself
 public static void CreateXML(string fileLocation, string _data)
 {
     StreamWriter writer;
     FileInfo t = new FileInfo(fileLocation);
     writer = t.CreateText();
     writer.Write(_data);
     writer.Close();
 }
开发者ID:jmdjr,项目名称:jd-bacon,代码行数:9,代码来源:JDGameUtilz.cs

示例15: CreateXML

    // Finally our save and load methods for the file itself
    void CreateXML(string dataToSerialize, string folder, string fileName)
    {
        StreamWriter writer;
        FileInfo saveFile = new FileInfo(folder+"\\"+ fileName);
        if(!saveFile.Exists)
        {
           writer = saveFile.CreateText();
        }
        else
        {
           saveFile.Delete();
           writer = saveFile.CreateText();
        }

        writer.Write(dataToSerialize);
        writer.Close();
        Debug.Log("File written.");
    }
开发者ID:quistador,项目名称:FOB,代码行数:19,代码来源:ObjectToXmlSerializer.cs


注:本文中的FileInfo.CreateText方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。