700字范文,内容丰富有趣,生活中的好帮手!
700字范文 > C# 去除文件或 文件夹只读属性

C# 去除文件或 文件夹只读属性

时间:2021-04-08 17:34:50

相关推荐

C# 去除文件或 文件夹只读属性

独角兽企业重金招聘Python工程师标准>>>

#region文件或文件夹去除只读属性

stringpath=@"C:\123.txt";

DirectoryInfodirInfo=newDirectoryInfo(path);

dirInfo.Attributes=FileAttributes.Normal|FileAttributes.Directory;

FileInfofileInfo=newFileInfo(path);

try

{

if(fileInfo.IsReadOnly)

{

File.SetAttributes(path,FileAttributes.Normal);

}

FileStreamfs=newFileStream(path,FileMode.Append,FileAccess.Write);

StreamWritersw=newStreamWriter(fs,Encoding.UTF8);

sw.WriteLine("AAA");

sw.Close();

fs.Close();

//fileInfo.Delete();

}

catch(System.Exceptionex)

{

Console.WriteLine(ex.ToString());

Console.ReadKey();

}

finally

{

}

Console.WriteLine("文件修改成功!");

Console.ReadKey();

#endregion

本内容不代表本网观点和政治立场,如有侵犯你的权益请联系我们处理。
网友评论
网友评论仅供其表达个人看法,并不表明网站立场。