Unity3d读写文件操作
来源:互联网 发布:fangcms源码下载 编辑:程序博客网 时间:2024/06/05 15:58
// Use this for initialization
void Start ()
{
string path="";
if(Application.platform==RuntimePlatform.Android)
{
path=Application.persistentDataPath;
}
else if(Application.platform==RuntimePlatform.WindowsPlayer)
{
path=Application.dataPath;
}
else if(Application.platform==RuntimePlatform.WindowsEditor)
{
path=Application.dataPath;
}
string configip=LoadFile(path,"test.txt");
if(configip!="error")
{
gameObject.GetComponent<UILabel>().text="read:"+configip;
}
else
{
createORwriteConfigFile(path,"test.txt","192.168.200.252");
string str=LoadFile(path,"test.txt");
gameObject.GetComponent<UILabel>().text="create:"+str;
}
}
/// <summary>
/// 在指定位置创建文件 如果文件已经存在则追加文件内容
/// </summary>
/// <param name='path'>
/// 路径
/// </param>
/// <param name='name'>
/// 文件名
/// </param>
/// <param name='info'>
/// 文件内容
/// </param>
private void createORwriteConfigFile(string path,string name,string info)
{
StreamWriter sw;
FileInfo t = new FileInfo(path+"//"+ name);
if(!t.Exists)
{
sw = t.CreateText();
}
else
{
sw = t.AppendText();
}
sw.WriteLine(info);
sw.Close();
sw.Dispose();
}
/// <summary>
/// 删除文件
/// </summary>
/// <param name='path'>
/// Path.
/// </param>
/// <param name='name'>
/// Name.
/// </param>
void DeleteFile(string path,string name)
{
File.Delete(path+"//"+ name);
}
/// <summary>
/// 读取文件内容 仅读取第一行
/// </summary>
/// <param name='path'>
/// Path.
/// </param>
/// <param name='name'>
/// Name.
/// </param>
private string LoadFile(string path,string name)
{
FileInfo t = new FileInfo(path+"//"+ name);
if(!t.Exists)
{
return "error";
}
StreamReader sr =null;
sr = File.OpenText(path+"//"+ name);
string line;
while ((line = sr.ReadLine()) != null)
{
break;
}
sr.Close();
sr.Dispose();
return line;
}
<script type="text/javascript"><!--google_ad_client = "ca-pub-1944176156128447";/* cnblogs 首页横幅 */google_ad_slot = "5419468456";google_ad_width = 728;google_ad_height = 90;//--></script><script type="text/javascript" src="http://pagead2.googlesyndication.com/pagead/show_ads.js"></script>
- Unity3d读写文件操作
- unity3d 简单的xml文件读写操作
- Unity3D-各平台文件读写操作路径目录
- Unity3D 读写XML文件
- Unity3D 读写 txt 文件
- Unity3D 读写 txt 文件
- Unity3D 读写XML文件
- unity3d文件读写
- Unity3d 读写XML文件
- Unity3D之文件读写
- unity3d读写XML文件
- Unity3d Json 读写文件
- Unity3D之文件读写文件
- unity3d C#文本读写操作
- Unity3d的文件读写笔记
- Unity3d如何读写XML文件
- unity3d ios 读写txt文件
- Unity3D工具类 - 读写文件
- 学习小记--android静态注册广播接收器之惑--6.6
- Windows Phone开发人员必看资料
- 通过DBCA安装Oracle 11g
- 帮助文档制作工具
- input标签、radio标签、checkbox标签、select标签
- Unity3d读写文件操作
- android中为TextView动态改变字体颜色,如点击时更改
- JAVA读取XML文件
- 有关HTML5学习资料
- UVALive 3644 X-Plosives
- DSS General Event-Based Derived Flow
- servlet规范版本的差异以及Tomcat各版本的支持情况
- Android资源目录assets及raw
- JS实现文本框获得焦点,文本框里提示信息自动消失