Exemplo n.º 1
0
 /// <summary>
 /// 获取路径文件里面的数据流
 /// </summary>
 /// <param name="path"></param>
 /// <returns></returns>
 public static byte[] GetTextAssetContentByteArr(this string path)
 {
     try
     {
         byte[] bs = null;
         lock (_locker)
         {
             using (FileStream fs = new FileStream(path, FileMode.Open, FileAccess.Read))
             {
                 bs = new byte[fs.Length];
                 fs.Read(bs, 0, bs.Length);
             }
         }
         return(bs);
     }
     catch (IOException e)
     {
         LogOperator.AddResErrorRecord("获取文件字符串时有误", e.Message, "文件路径:", path);
         return(null);
     }
 }
Exemplo n.º 2
0
 /// <summary>
 /// 获取路径文件里面的数据流
 /// </summary>
 /// <param name="path"></param>
 /// <returns></returns>
 public static byte[] GetTextAssetContentByteArr(this string path)
 {
     try
     {
         byte[] bs = null;
         lock (_locker)
         {
             FileInfo fi = new FileInfo(path);
             bs = new byte[fi.Length];
             using (FileStream fs = fi.OpenRead())
             {
                 fs.Read(bs, 0, Convert.ToInt32(fs.Length));
             }
         }
         return(bs);
     }
     catch (IOException e)
     {
         LogOperator.AddResErrorRecord("获取文件字符串时有误", e.Message, "文件路径:", path);
         return(null);
     }
 }
Exemplo n.º 3
0
 /// <summary>
 /// 获取路径文件里面的字符串内容,格式为utf-8
 /// </summary>
 /// <param name="path"></param>
 /// <returns></returns>
 public static string GetTextAssetContentStr(this string path)
 {
     try
     {
         string content = null;
         lock (_locker)
         {
             using (FileStream fs = new FileStream(path, FileMode.Open, FileAccess.Read))
             {
                 using (StreamReader sr = new StreamReader(fs))
                 {
                     content = sr.ReadToEnd();
                 }
             }
         }
         return(content);
     }
     catch (IOException e)
     {
         LogOperator.AddResErrorRecord("获取文件字符串时有误", e.Message, "文件路径:", path);
         return(null);
     }
 }