C# 去除文件或 文件夹只读属性
2019獨角獸企業重金招聘Python工程師標準>>>
?#region?文件?或文件夾?去除只讀屬性
????????????string?path?=?@"C:\123.txt";
?
????????????DirectoryInfo?dirInfo?=?new?DirectoryInfo(path);
????????????dirInfo.Attributes?=?FileAttributes.Normal?|?FileAttributes.Directory;
?
????????????FileInfo?fileInfo?=?new?FileInfo(path);
????????????try
????????????{
????????????????if?(fileInfo.IsReadOnly)
????????????????{
????????????????????File.SetAttributes(path,?FileAttributes.Normal);
????????????????}
????????????????FileStream?fs?=?new?FileStream(path,?FileMode.Append,?FileAccess.Write);
????????????????StreamWriter?sw?=?new?StreamWriter(fs,?Encoding.UTF8);
????????????????sw.WriteLine("AAA");
????????????????sw.Close();
????????????????fs.Close();
????????????????//fileInfo.Delete();
????????????}
????????????catch?(System.Exception?ex)
????????????{
????????????????Console.WriteLine(ex.ToString());
????????????????Console.ReadKey();
????????????}
????????????finally
????????????{
?
????????????}
????????????Console.WriteLine("文件修改成功!");
????????????Console.ReadKey();
?
????????????#endregion
轉載于:https://my.oschina.net/guanxinsui/blog/956574
總結
以上是生活随笔為你收集整理的C# 去除文件或 文件夹只读属性的全部內容,希望文章能夠幫你解決所遇到的問題。
- 上一篇: 13代酷睿i9+满血4060显卡!华硕天
- 下一篇: 电脑桌面背景变成黑色的了是为什么