独角兽企业重金招聘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