当前位置:网站首页>About C unity read / write file
About C unity read / write file
2022-06-09 20:31:00 【charlsdm】
I wrote a text class about text reading and writing
using System.Collections;
using System.Collections.Generic;
using UnityEngine;
using MyGameFrameWork;
using System.IO;
public class CreateTextContentMgr : BaseManager<CreateTextContentMgr>
{
// Start is called before the first frame update
/// <summary>
/// Create one directly and write to txt Content
/// </summary>
/// <param name="text"></param>
public static void AddTextFileStream(string text)
{
string path = Application.dataPath + "/TextFile/TextFile.txt";
FileStream file = new FileStream(path, FileMode.Create);
byte[] bts = System.Text.Encoding.UTF8.GetBytes(text);
file.Write(bts, 0, bts.Length);
if(file!=null)
{
file.Flush();
file.Close();
file.Dispose();
}
}
/// <summary>
/// Add directly Text On the text
/// </summary>
public static void AddTextAppedInfo(string text)
{
string path = Application.dataPath + "/TextFile/TextFile.txt";
StreamWriter sw;
FileInfo fi = new FileInfo(path);
if(!File.Exists(path))
{
sw = fi.CreateText();
}
else
{
sw = fi.AppendText();
}
sw.WriteLine(text);
sw.Close();
sw.Dispose();
}
public static string ReadTxtAllInfo()
{
string path = Application.dataPath + "/TextFile/TextFile.txt";
StreamReader strr = new StreamReader(path);
string str = strr.ReadToEnd();
return str;
}
}
边栏推荐
猜你喜欢

Bug in upgrading SD card / TF card of HMI serial interface screen

College community management system

Neo4j桌面版數據庫備份

Skills and experience of product planning

NoSQL redis configuration and optimization (I blew the night breeze of Qinhuai River for you when you were not in Nanjing)

Target Segmentation -- semantic segmentation of multi category dataset by Unet

HMI 联机下载失败的问题及解决方案
![[MySQL] principle and construction of master-slave replication](/img/02/c0fec31d55ef20975bd3de2580e8c6.png)
[MySQL] principle and construction of master-slave replication

卡尔曼滤波(KF)无迹卡尔曼滤波(UKF)

After 1995, programmers in big factories were sentenced to 9 months for deleting databases
随机推荐
杰理之有关摄像头的应用【篇】
MobX初探
C#Random的作用
Alibaba cloud 22q1 status summary, where are you going
Anlu technology released new SF1 series fpsoc products: high integration and low power consumption, helping to realize a variety of application scenarios
上海光机所两名员工核酸阳性,园区367人将被转运
TypeScript 变量声明
Falling ant
这6种实现负载均衡技术的方式不容错过
【mysql】主从复制原理、搭建
Neo4j desktop database backup
高通:将坚持多元化的代工战略,关注英特尔代工商务合作条件
下载最新的全球疫情历史数据,下载到当前日前两天
Sauvegarde de la base de données neo4j Desktop
Qualcomm: it will adhere to the diversified OEM strategy and pay attention to the business cooperation conditions of Intel OEM
C#中的匿名函数的应用
杰理之蓝牙配网【篇】
95後大廠程序員删庫被判刑9個月
博文推荐|BookKeeper - Apache Pulsar 高可用 / 强一致 / 低延迟的存储实现
【opencvsharpDNN】OpenCvSharp中YoloV3和Caffe的实现示例