string sPath = "f://Document//test";
               
         if (!Directory.Exists(sPath))
                {
                    Directory.CreateDirectory(sPath);
                }   FileStream myfs = new FileStream(sPath, FileMode.Create);
   StreamWriter sw = new StreamWriter(myfs);    for (int i = 0; i < list.Count; i++)
                {
                    sw.WriteLine(list[i] + " ");                }                sw.Flush();
                sw.Close();提示说对路径“f:\Document\test”的访问被拒绝。是怎么回事呢?谢谢~~c#

解决方案 »

  1.   

    改下这行代码看看
    FileStream myfs = new FileStream(sPath, FileMode.Create,FileAccess.ReadWrite);
      

  2.   

    你用FileStream里面的参数是文件名,不是目录路径
      

  3.   

    string sPath = "f://Document//test";//文件路径
    string fPath = "f://Document";//文件夹             
             if (!Directory.Exists(fPath ))
                    {
                        Directory.CreateDirectory(fPath );
                    }   FileStream myfs = new FileStream(sPath, FileMode.OpenOrCreate);
       StreamWriter sw = new StreamWriter(myfs);    for (int i = 0; i < list.Count; i++)
                    {
                        sw.WriteLine(list[i] + " ");                }                sw.Flush();
                    sw.Close();
      

  4.   

      string sPath = "f://Document//test";
    这应该还有文件的后缀吧!
    提示“拒绝访问”说明你的操作权限不够,最好把你要操作的文件放在非系统盘。
      

  5.   

    string sPath = "f://Document//test"是路径,
    Directory.CreateDirectory(sPath);这句代码创建了一个f://Document//test的文件夹FileStream myfs = new FileStream(sPath, FileMode.Create);错误在这,sPath只是路径,并没有指定文件名,楼主如果是想在f://Document//test创建文件,还要指定文件名及后缀,可以改成这样FileStream myfs = new FileStream(sPath+"//test.txt", FileMode.Create);//在sPath的目录下创建test.txt
      

  6.   

    第一,sPath 到底是文件名还是路径名?你要写清楚,因为你前边有判断 if (!Directory.Exists(sPath))
                    {
                        Directory.CreateDirectory(sPath);
                    }
    所以,我认为你是路径名,那么,接下来你要把文件名给定义清楚。
      

  7.   

    第二,你用完myfs 之后,要把它Close掉。