在项目路径下写入文件
string s;
Regex reg = new Regex(@"(?i)\\[uU]([0-9a-f]{4})");
s = reg.Replace( s, delegate (Match m)
{
return ((char)Convert.ToInt32(m.Groups[1].Value, 16)).ToString();
});
string DeletePath = Application.dataPath + "/TextData.txt";
StreamWriter sw;
FileInfo fi = new FileInfo(DeletePath);
if (!File.Exists(DeletePath))
{
sw = fi.CreateText();
//写入文件
sw.WriteLine(s);
sw.Close();
sw.Dispose();
}
else
{
string FileUrl = Application.dataPath + "/TextData.txt";
File.WriteAllText(FileUrl, s, Encoding.UTF8);
}
在电脑其他盘中写入文件
string path = @"C:/Data";
if (!Directory.Exists(path))
{
Directory.CreateDirectory(path);
}
string filepath = path + @"/json.json";
if (!File.Exists(filepath))
{
FileStream file = File.Create(filepath);
file.Dispose();
}
string s;
Regex reg = new Regex(@"(?i)\\[uU]([0-9a-f]{4})");
s = reg.Replace(da.ToJson(), delegate (Match m)
{
return ((char)Convert.ToInt32(m.Groups[1].Value, 16)).ToString();
});
File.WriteAllText(filepath, s, Encoding.UTF8);