本文整理汇总了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();
}
示例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
}
示例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();
}
示例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();
}
示例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();
}
示例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(); // 销毁流
}
示例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 ();
}
示例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;
}
}
示例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();
}
示例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.");
}
示例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 ();
}
}
示例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();
}
示例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.");
}
示例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();
}
示例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.");
}