c# wince 文本操作
来源:互联网 发布:在淘宝买到假货怎么办 编辑:程序博客网 时间:2024/05/22 06:22
c# wince 文本操作internal class TxtManager { private static string appPath = System.IO.Path.GetDirectoryName( System.Reflection.Assembly.GetExecutingAssembly().GetName().CodeBase.ToString()); private static string dbSetTxtA = appPath + @"\DB_Set_A.ini"; //设置的文本文件 private static string dbSetTxtB = appPath + @"\DB_Set_B.ini"; //用来临时存储A中的内容 public string[,] readDBSetTxtA() //读取文本文件 存储到数组中 { StreamReader sr; FileStream fs = new FileStream(dbSetTxtA, FileMode.Open, FileAccess.Read); sr = new StreamReader(fs); string strLine = sr.ReadLine(); string[,] result = new string[10, 20]; int i = 0; while (strLine != null) // { //string _serial = ""; //string _sign = ""; //string _data = ""; //11 11 11 11 11 01 04 250 200 50 12 40 2.836226 16 50 0 1000 822.4379 1 20 //0 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 string[] arrTxt = strLine.Split(' '); for (int j = 0; j < arrTxt.Length; j++) { result[i, j] = arrTxt[j]; } strLine = sr.ReadLine(); i++; } return result; } public void writeTxt(byte[] serial, byte[] sign, float[] data) //写文本文件 如果关键值 在数组文本中不存在 则将数组的内容写到文本中 { string _serial = ""; string _sign = ""; string _data = ""; string _stringAll = ""; string _serial_sign = ""; for (int i = 0; i < serial.Length; i++) { _serial = _serial + " " + serial[i].ToString("X2"); } for (int i = 0; i < sign.Length; i++) { _sign = _sign + " " + sign[i].ToString("X2"); } for (int i = 0; i < data.Length; i++) { _data = _data + " " + data[i].ToString(); } _serial_sign = _serial.Trim() + " " + _sign.Trim(); _stringAll = _serial_sign + " " + _data.Trim(); StreamWriter sw; StreamReader sr; if (File.Exists(dbSetTxtA)) //文本文件存在 { //该处目的 将以前设置内容备份, //新写入A中内容,之后读取以前设置的内容,如果已经含有现写入A中的设备的设置,则B中的内容不导入到A中 //保证A中每个设备的设置都是最新的 File.Copy(dbSetTxtA, dbSetTxtB, true); sw = new StreamWriter(dbSetTxtA, false); //程序路径下不存在文本文件,则 创建文本文件 sw.WriteLine(_stringAll.Trim()); //将设置内容写到dbSetTxtA FileStream fs = new FileStream(dbSetTxtB, FileMode.Open, FileAccess.Read); sr = new StreamReader(fs); string strLine = sr.ReadLine(); while (strLine != null) // { // MessageBox.Show(strLine.Substring(0, _serial_sign.Length) + "\n" + _serial_sign); //如果B中的“区域值+" "+设备值”在A刚写入的内容中存在 说明该内容被更新 if (strLine.Substring(0, _serial_sign.Length) == _serial_sign) { //存在则不添加 } else { sw.WriteLine(strLine); } strLine = sr.ReadLine(); } sr.Close(); sw.Close(); File.Delete(dbSetTxtB); } else { sw = new StreamWriter(dbSetTxtA); //程序路径下不存在文本文件,则 创建文本文件 sw.WriteLine(_stringAll.Trim()); sw.Close(); } } }
网上转的,不错
- c# wince 文本操作
- WINCE 文本读写操作总结
- WINCE 文本读写操作总结
- c# 中操作文本
- C# 操作记事本文本
- unity3d C#文本读写操作
- WINCE下用C#操作S3C2440GPIO引脚
- C#文本操作的所有方法
- C#操作word之文本替换
- C#操作word之文本批量替换
- c#操作txt文本之查询
- c#操作txt文本之写入
- C# 创建目录 写入文本 基础文本操作
- 用C#操作类读写WinCE平台Mac地址
- 用C#操作类读写WinCE平台Mac地址
- WinCE的C#中使用StreamReader 来读取TXT文档,读取文本文档。
- C#实现在Excel中搜索文本(遍历操作)
- C#操作文本读写流--- StreamWritter and StreamReader
- 希尔排序学习心得
- shell [ printf / set / shift 用法初见]
- 利用ODBC连接数据库
- ORACLE学习笔记(一)——数据库启动(nomount)
- 润乾报表连接mysql数据源别名问题
- c# wince 文本操作
- java 实现关机工具,托盘图标
- stosb指令解析
- 产后复原:预防胸/部下垂
- 高德地图-绘制个人历史位置路线
- 初步认识asp.net中导入excell
- loadsb指令解析
- checkstyle插件问题总结
- 导入项目出现Project has no default.properties file错误总结