移动端外部配置文件读写

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

最后编辑于
©著作权归作者所有,转载或内容合作请联系作者
【社区内容提示】社区部分内容疑似由AI辅助生成,浏览时请结合常识与多方信息审慎甄别。
平台声明:文章内容(如有图片或视频亦包括在内)由作者上传并发布,文章内容仅代表作者本人观点,简书系信息发布平台,仅提供信息存储服务。

相关阅读更多精彩内容

  • Android 自定义View的各种姿势1 Activity的显示之ViewRootImpl详解 Activity...
    passiontim阅读 179,276评论 25 708
  • 现在的我,越来越相信一件事那就是坚持是一种能力,一种多数人拥有,而多数人缺乏的一个意识与品质,诸如在很多小方面你可...
    龙御宸阅读 280评论 0 0
  • 《面纱》书评 特别喜欢毛姆的书,看他的月亮与六便士的时候会觉得很神奇,思特里克兰德追求梦想的语气让我觉得很羡慕,我...
    一个特立独行的西瓜阅读 1,200评论 2 24
  • 卖高价宠物狗的套路 概要:小狗,3个月大领来养,养2个月,就可以出售了。 细节:领养后,即3个月大时,开始拍摄一组...
    仲兄阅读 656评论 0 0
  • 喜欢一碗面,鲍鱼素椒面。原因很简单有妈妈的味道。产自虞山面馆! 我喜欢吃面,我喜欢做面。我会做很多奇怪的面。生活在...
    Mandy萍阅读 338评论 0 0

友情链接更多精彩内容