现在需要构建出一个文件来,在把一个文件的内容添加到另一个文件后,旧文件中的中文到新文件中全变成了乱码,数字/字母正常现在的操作方法是:
//复制文件内容的方法
public static string AppendFile(string srcFileName, string aimFileName)
{
string result = "";
StreamReader SR = null;
try
{
string S;
SR = 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);
}请问要如何才能让原来文件中的内容不更改的添加到新文件中呢?
//复制文件内容的方法
public static string AppendFile(string srcFileName, string aimFileName)
{
string result = "";
StreamReader SR = null;
try
{
string S;
SR = 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);
}请问要如何才能让原来文件中的内容不更改的添加到新文件中呢?
解决方案 »
- C#GDI+绘制一个椭圆,如何判断某个点是否在椭圆上?
- c#与Flash交互
- 请教下怎么去掉字符串前面的0,如"00200"我只要200
- Oracle:求一条sql语句?
- C#从大图片中截取一小块的问题
- [SQL问题]请教怎样在select语句where Cid=后面加一个变化的值.具体如正文
- 做了一个处理复杂的程序,CPU占有率100%,电脑处于死机状态
- 我要汇总数据库中某一例..解决性能问题
- c#新手,问问题!-----1
- 用C#与ASP.NET开发网页,可以不用VBScript与JSP吗?开发的网页是否可以用WIN98的IE5.0浏览?
- c# 数组 筛选 重复的值
- VC++2005 中动态添加的控件的事件处理问题(C#一样可以解决,所以我到C#来提问)
StreamReader,StreamWriterStreamWriter sw = new StreamWriter(path,Encoding.Default);
您能指导一下我该怎么修改我的方法吗?
换成 SR = new StreamWriter(srcFileName,Encoding.Default);
这样改不行呢~
//复制文件内容的方法
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);
}