代码之家  ›  专栏  ›  技术社区  ›  Developer

我怎样才能打开一个长度应该是94倍的文件

  •  1
  • Developer  · 技术社区  · 14 年前

    我想用“打开文件”对话框打开一个文件。如果打开的文件长度是94的倍数,我想打开该文件,如果不是,我想抛出一个错误消息

    3 回复  |  直到 14 年前
        1
  •  4
  •   Justin    14 年前
    if(new FileInfo(path).Length % 94 == 0)
    {
       using(var reader = new StreamReader(path))
       {
           ...
       }
    }
    else 
        throw new ArgumentException("File-length not multiple of 94", "path");
    
        2
  •  1
  •   deepcode.co.uk    14 年前

    奇怪的问题!怎么样。。。。

    if( file.Length % 94 ) throw.....
    
        3
  •  1
  •   Jon Skeet    14 年前

    if (new FileInfo(filename).Length % 94 != 0)
    {
        ...
    }
    

    您可能需要设置 OpenFileDialog.CheckFileExists 或者在测量长度之前进行手动检查。