解压缩bz2文件时如何修复System.UnauthorizedAccessException?

时间:2011-07-15 20:06:09

标签: c# permissions sharpziplib

我尝试使用ICSharpCode.SharpZipLib通过代码解压缩bz2文件。

似乎无论我在哪里创建我的文件,即使我有完全访问控制权,我仍然得到这个例外。非常感谢任何帮助。

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);                
        }       
    }
}

2 个答案:

答案 0 :(得分:1)

您的代码无法在桌面上创建新路径。 检查"C:\\Users\\mike\\Desktop\\Decompressed"的权限。

答案 1 :(得分:0)

也许,你应该这样写:

string decompressPath = "C:\\Users\\mike\\Desktop\\Decompressed\\opinions.tsv";
相关问题