zoukankan      html  css  js  c++  java
  • 相同文件只能一个进程读取

           string straa = ReadFile(file.FullName, FileAccess.Read, FileShare.None);

           private string ReadFile(string strFilePath,FileAccess fileAccess, FileShare fileShare)
            {
                try
                {
                    FileStream fs = new FileStream(strFilePath, FileMode.Open, fileAccess, fileShare);
                    var buffer = new byte[fs.Length];
                    fs.Position = 0;
                    fs.Read(buffer, 0, buffer.Length);
                    return Encoding.UTF8.GetString(buffer);
                }
                catch (System.IO.IOException ex)
                {
                    ///正由另一进程使用,因此该进程无法访问该文件
                    throw (ex);
                }
                catch (Exception ex)
                {
                    throw (ex);
                } 
            }

  • 相关阅读:
    kotlin中值范围
    kotlin中集合
    kotlin数据解构
    Java 8 Lambda 表达式
    kotlin 之内联函数
    kotlin之函数的范围和泛型函数
    kotlin函数的参数和返回值
    kotlin 之单表达式函数
    kotlin使用中辍标记法调用函数
    kotlin之函数的基本用法
  • 原文地址:https://www.cnblogs.com/amylis_chen/p/2816252.html
Copyright © 2011-2022 走看看