向手机缓存区写入Text
来源:互联网 发布:中科院在职研究生知乎 编辑:程序博客网 时间:2024/04/20 04:07
1.PC端读取Resources文件夹下的.txt文件,并解析分为一行一行存入ArrayList
2.Android端如果文件不存在则在缓存区创建一个.txt,并将Resources文件夹下.test.txt文件信息复制写入新创建的.txt中
/// <summary> /// 获取当前平台路径 /// </summary> void GetPlatformPath() { if(Application .platform ==RuntimePlatform.Android ) { PathSource = Application.persistentDataPath; //test.txt,文件流写入和创建需要文件后缀名 } else if(Application.platform==RuntimePlatform.WindowsEditor||Application .platform ==RuntimePlatform.WindowsPlayer ) { PathSource = Application.dataPath; //testpc端Resources读取不需要后缀名 } }
//android端方法
ArrayList FunAndroid() { StreamWriter wt; FileInfo t = new FileInfo(PathSource + "//" + ConfigPath); if (!t.Exists) { wt = t.CreateText(); TextAsset te = Resources.Load(ConfigPathName) as TextAsset; string strs = Encoding.UTF8.GetString(te.bytes); if (te != null) { wt.Write(strs, 0, 1024); wt.Close(); wt.Dispose(); } Debug.Log("-----------dont have ,creat one"); } else { StreamReader sr = null; try { sr = File.OpenText(PathSource + "//" + ConfigPath); } catch (System.Exception e) { return null; } string line; ArrayList arrlist = new ArrayList(); while ((line = sr.ReadLine()) != null) { arrlist.Add(line); } sr.Close(); sr.Dispose(); return arrlist; } return null; }
//pc端方法
ArrayList FunPc() { TextAsset te = Resources.Load(ConfigPathName) as TextAsset; if (te != null) { string tempStr = te.text; string[] Strs = tempStr.Split('\n'); if (Strs.Length > 0) { ArrayList arrlist = new ArrayList(); for (int i = 0; i < Strs.Length; i++) { arrlist.Add(Strs[i]); } return arrlist; } return null; } else { return null; } }
//联合
ArrayList GetFile() { if(Application .platform ==RuntimePlatform.Android ) { FunAndroid(); } else if (Application.platform == RuntimePlatform.WindowsEditor || Application.platform == RuntimePlatform.WindowsPlayer) { FunPc(); } return null; }
//临时给.txt写入信息 public void Test() { StreamWriter wt; //在文件后面添加写入信息 FileInfo fi = new FileInfo(PathSource + "//" + ConfigPath); wt = fi.AppendText();//如果直接重新写入,不需要在原文件后面追加内容则用fi.CreateText (); string strs = "\n"+"ab,25,100"; wt.WriteLine(strs); wt.Close(); wt.Dispose(); Debug.Log("-----------add -------------"); }
阅读全文
0 0
- 向手机缓存区写入Text
- android向本地写入缓存
- adb向手机写入文件,Read-only file system
- C# 读取text内容并向text写入内容,对文本进行读写
- 在QTP中向记事本里写入“HHHHH”并保存为text.txt
- C#读取/写入Text
- 使用UIAutomator在Android6.0执行,无法向手机SD卡写入内容问题的解决
- 向图片写入文字!
- 向文本文件中写入
- 向文件写入文本
- 硬盘写入缓存
- 写入缓存公共类
- thinkphp 缓存写入失败
- php 写入缓存
- PHP写入text的方法
- 把字节流转化成bitmap对象,从Intent中获取Ndef对象,向手机根目录中写入文件
- 数据读取/写入——线型缓存区
- 数据读取/写入——环型缓存区
- Qt:终于来了!基于QML和WebGL开发网页端
- 20170920_chr_Struts2Cal_model 计算器模型驱动
- 基于HTML5定位使用PHP+MySQL搜索附近的人并AJAX返回结果
- 从零编程基础小白到专业数据分析师,你需要走多远
- VsVim使用教程(以及简要vim介绍)
- 向手机缓存区写入Text
- pycaffe的使用
- C语言猜拳小游戏,课堂设计
- The TensorFlow library wasn't compiled to use SSE instructions, but these are avail、原因及解决办法
- 第四周实践项目8 C++标准模板库与数据结构的学习
- mysqldump备份和还原&&使用mysqldump备份和恢复所有数据库
- eclipse编辑环境的美化——eclipse color theme的使用
- Java+ selenium+maven截图方法TakeScreenshot
- 通过junit/TestNG+java简单实现接口的自动化测试