首页 > 代码库 > 读取本地txt配置文件,获取ServerIP
读取本地txt配置文件,获取ServerIP
1.
2.
3.
4.
5.
6.
7.
private void CreateTxt(string filename)
{
if (filename == "")
{
Debug.LogError("请输入文件名");
return;
}
string filePath = Application.dataPath + "/StreamingAssets" + "/" + filename;
if (!File.Exists(filePath))
{
FileStream fs1 = new FileStream(filePath, FileMode.Create, FileAccess.Write);//创建写入文件
StreamWriter sw = new StreamWriter(fs1);
sw.WriteLine("hhhhhh--");//开始写入值
sw.Close();
fs1.Close();
//Console.WriteLine("txt no exit");
}
}
private void ReadTxt(string filename)
{
string filePath = Application.dataPath + "/StreamingAssets" + "/" + filename;
if (!File.Exists(filePath))
{
Debug.LogError("文件不存在");
return;
}
else
{
FileStream fs = new FileStream(filePath, FileMode.Open, FileAccess.Read);
StreamReader sr = new StreamReader(fs);
string fileContent = sr.ReadToEnd();
readTxtContent.text = fileContent;
sr.Close();
fs.Close();
}
}
private void WriteTxt(string filename)
{
string filePath = Application.dataPath + "/StreamingAssets" + "/" + filename;
if (!File.Exists(filePath))
{
Debug.LogError("文件不存在");
return;
}
else
{
FileStream fs = new FileStream(filePath, FileMode.Open, FileAccess.Write);
StreamWriter sw = new StreamWriter(fs);
sw.WriteLine(writeTxtContent.text);//开始写入值
sw.Close();
fs.Close();
}
}
读取本地txt配置文件,获取ServerIP