2011-07-15 84 views
0

我試圖通過使用ICSharpCode.SharpZipLib的代碼解壓縮一個bz2文件。解壓縮bz2文件時如何解決System.UnauthorizedAccessException?

似乎無論我在哪裏製作我的文件,即使我已對其進行了FULL ACCESS控制,我仍然會收到此異常。任何幫助不勝感激。

using System; 
using System.IO; 

using ICSharpCode.SharpZipLib.BZip2; 

namespace decompressor 
{ 
    class MainClass 
    { 
     public static void Main(string[] args) 
     { 
      string filePath = "C:\\FreeBase\\opinions.tsv.bz2"; 
      string decompressPath = "C:\\Users\\mike\\Desktop\\Decompressed"; 

      Console.WriteLine("Decompressing {0} to {1}", file, path); 
      BZip2.Decompress(File.OpenRead(filePath),File.OpenWrite(decompressPath), true);     
     }  
    } 
} 

回答

1

您的代碼無法在桌面上創建新路徑。 檢查"C:\\Users\\mike\\Desktop\\Decompressed"的權限。

+0

我不是創建一個路徑,它已經存在。 – tap

+1

那麼你爲什麼使用這個:'File.Create(path)'?你的代碼是否擁有該文件的權限? – VMAtm

0

也許,你應該這麼寫:

string decompressPath = "C:\\Users\\mike\\Desktop\\Decompressed\\opinions.tsv";