zoukankan      html  css  js  c++  java
  • WPF C# 字符串读写文件

    WPF C# 字符串读写文件

    
    public class 字符串读写文件
    {
            /// <summary>
            /// Encoding.Unicode.GetString 如果使用Encoding.Default.GetString 会错
            /// </summary>
            public 字符串读写文件()
            {
              f_文件地址="文件";
            }
            public bool x_写文件(string str)
            {            
                FileStream xiaFile = new FileStream(f_文件地址 , FileMode.Create);
                byte[] buf = Encoding.Unicode.GetBytes(str);
                xiaFile.Write(buf , 0 , buf.Length);
                xiaFile.Flush();
                xiaFile.Close();
                return true;
            }
    
            /// <summary>
            /// 读文件
            /// </summary>
            /// <param name="str">读文件内容保存到str</param>
            /// <returns>读文件成功返回true</returns>
            public bool d_读文件(out string str)
            {
                FileInfo fi = new FileInfo(f_文件地址);
                long len = fi.Length;
    
                FileStream fs = new FileStream(f_文件地址 , FileMode.Open);
                byte[] buffer = new byte[len];            
                fs.Read(buffer , 0 , (int)len);
                fs.Close();
                str = Encoding.Unicode.GetString(buffer);
                return true;
            }
            private string f_文件地址;      
    }        
  • 相关阅读:
    HTTP 的学习
    标量方程求解
    限制器
    差分格式
    Archlinux的基本配置
    布拉休斯方程数值求解
    GNU大型项目构建和覆盖率生成(第一篇)
    plot3d网格读取写入与可视化
    abaqus中的约束
    向量范数和矩阵范数
  • 原文地址:https://www.cnblogs.com/lindexi/p/12087807.html
Copyright © 2011-2022 走看看