美文网首页总结Unity知识归纳
移动端外部配置文件读写

移动端外部配置文件读写

作者: IongX | 来源:发表于2017-04-11 15:23 被阅读8次
    using System.Collections;
    using System.Collections.Generic;
    using UnityEngine;
    using UnityEngine.UI;
    using System.IO;
    using System;
    public class DoFileTest : MonoBehaviour {
    
        public Text PathText;
        public Text ResultText;
        public InputField TestField;
    
        public string filepath;
        // Use this for initialization
        void Start ()
        {
            filepath = Application.persistentDataPath + "/file.txt";
            PathText.text = filepath;
        }
        
        public void ReadFile()
        {
            try
            {
                StreamReader sr = new StreamReader(filepath);
                string ss = sr.ReadToEnd();
                Debug.Log(ss);
                ResultText.text = ss;
            }catch(Exception e)
            {
                ResultText.text = e.Message;
            }
    
        }
    
    
        public void OnBtnClick()
        {
            Debug.Log(TestField.text + "       shengc");
            try
            {
                FileStream fs = new FileStream(filepath, FileMode.Create);
                byte[] bytes = System.Text.Encoding.UTF8.GetBytes(TestField.text);
                fs.Write(bytes, 0, bytes.Length);
                fs.Flush();
                fs.Close();         
            }
            catch(Exception e)
            {
                Debug.Log("保存失败!!!!");
            }
    
        }
    }
    
    

    unity3d读取外部文件详细 :

    http://www.cnblogs.com/murongxiaopifu/p/4199541.html

    相关文章

      网友评论

        本文标题:移动端外部配置文件读写

        本文链接:https://www.haomeiwen.com/subject/owxuattx.html