|
I want to write a small tool in C # to construct some VBScript, nsi files, but I found that the file format is UTF-8 (part of the content is C # program to judge the construction of the string itself, and the other part is prepared in advance Read out the files, those file formats are ANSI). Now I find that the Chinese in the generated files have become garbled, and even the 'sign behind the Chinese string disappears, causing vbscript to be unusable.
Is there any way to make the generated file also ansi format and guarantee that no garbled characters appear?
The method of copying files and writing files (that is, generating new files by these two methods):
1. Copy file
public static string CopyFile (string srcFileName, string aimFileName)
{
string result = "";
StreamReader SR = null;
try
{
string S;
SR = new StreamReader (srcFileName, Encoding.Default); // File.OpenText (srcFileName);
S = SR.ReadLine ();
while (S! = null)
{
AppendToFile (aimFileName, S);
//Console.WriteLine(S);
S = SR.ReadLine ();
}
}
catch (Exception e)
{
string s = e.ToString ();
throw;
}
finally
{
if (SR! = null)
SR.Close ();
}
return (result);
}
2. Write file
public static bool AppendToFile (string filepath, string comment)
{
StreamWriter SW;
SW = File.AppendText (filepath);
SW.WriteLine (comment);
SW.Close ();
return true;
} |
|