I altered my code so I could open a file as read only. Now I am having trouble using File.WriteAllText
because my FileStream
and StreamReader
are not converted to a string.
This is my code:
static void Main(string[] args)
{
string inputPath = @"C:Documents and SettingsAll UsersApplication Data"
+ @"MicrosoftWindows NTMSFaxActivityLogOutboxLOG.txt";
string outputPath = @"C:FAXLOGOutboxLOG.txt";
var fs = new FileStream(inputPath, FileMode.Open, FileAccess.Read,
FileShare.ReadWrite | FileShare.Delete);
string content = new StreamReader(fs, Encoding.Unicode);
// string content = File.ReadAllText(inputPath, Encoding.Unicode);
File.WriteAllText(outputPath, content, Encoding.UTF8);
}
See Question&Answers more detail:
os 与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…