请问我用StreamWriter写文件,用myStream.WriteLine("****")一行一行的写,可是我发现,有时候明明应该是在一行中的东西,会自动还行,例如我写myStream.WriteLine("asdfghjkl"),结果我在文件中看到的是
asdfgh
jkl
就是在j前面自动还行了,我试过就算写成myStream.WriteLine("kkkk\nkkk"),结果文件中也是
kkkk\nkkk
应该不是\n还行符的原因,请问大家,到底是怎么回事????在线等回复,谢谢.

解决方案 »

  1.   

    没有你说的那种情况using System;
    using System.Xml;
    using System.IO;
    public class Sample {
    static void Main() 
    {
    StreamWriter myStream = new StreamWriter(@"c:\x.txt");
    myStream.WriteLine("asdfghjkl");
    myStream.WriteLine("asdfghjkl");
    myStream.WriteLine("asdfghjkl");
    myStream.WriteLine("kkkk" + myStream.NewLine + "kkk");
    myStream.Close();
    }
    }
      

  2.   

    !@#^&*^(*(
    跟自动换行没什么关系
    我的代码:for (int i=0;i<DS.Tables["zhong"].Rows.Count;i++)
    {
    string strZhong=DS.Tables["zhong"].Rows[i][1].ToString().Replace("&","");
    strZhong=strZhong.Trim();
    string strYing=DS.Tables["zhong"].Rows[i][0].ToString();
    strYing=strYing.Trim();
    myStream.WriteLine("<Tu><Tuv Lang=\"EN-US\">"+strYing+"</Tuv><Tuv Lang=\"ZH-CN\"><df Font=\"SimSun\"><df Font=\"SimSun\"><df Font=\"SimSun\">"+strZhong+"</df></df></df></Tuv></Tu>");
    }他不是每行都换,每次200多行有一个换的,而且还行的地方的前面大多是"。"或者" "
      

  3.   

    不可能的,检查你的程序,在linux系统下也不可能的。
      

  4.   

    不行,我崩溃了,还是这个错误
    我的完整代码:
    FileStream fs=new FileStream(strexe+"/xml1.xml",FileMode.OpenOrCreate,FileAccess.Write);
    StreamWriter myStream=new StreamWriter(fs);
    myStream.BaseStream.Seek(0,SeekOrigin.Begin);
    FileStream fs1=new FileStream(strexe+"/xml.xml",FileMode.OpenOrCreate,FileAccess.Read);
    StreamReader myStream1=new StreamReader(fs1);
    myStream1.BaseStream.Seek(0,SeekOrigin.Begin);
    int intFL=0;
    string strR="";
    label2.Text="正在保存,请稍候.";
    label2.Visible=true;
    while (myStream1.Peek()!=-1&&intFL==0)
    {label2.Refresh();
    strR=myStream1.ReadLine();
    if (strR.IndexOf("<Tu>",0,strR.Length)>=0)
    {
    string strJ=strR.Remove(strR.IndexOf("<Tu>",0,strR.Length),strR.Length-strR.IndexOf("<Tu>",0,strR.Length));
    myStream.Write(strJ);
    intFL=1;
    }
    else
    {
    myStream.WriteLine(strR);
    }
    }
    string strsel2="select 英文,中文 from zhong";
    try
    {
    DS.Tables["zhong"].Clear();
    }
    catch{}
    OleDbDataAdapter Ad2=new OleDbDataAdapter(strsel2,Conn);
    Ad2.Fill(DS,"zhong");
    for (int i=0;i<DS.Tables["zhong"].Rows.Count;i++)
    {
    label2.Refresh();
    string strYr=DS.Tables["zhong"].Rows[i][0].ToString();
    string strZr=DS.Tables["zhong"].Rows[i][1].ToString();
    strYr=strYr.Replace("\r\n","");
    strZr=strZr.Replace("\r\n","");
    myStream.WriteLine("<Tu><Tuv Lang=\"EN-US\">"+strYr+"</Tuv><Tuv Lang=\"ZH-CN\"><df Font=\"SimSun\"><df Font=\"SimSun\"><df Font=\"SimSun\">"+strZr+"</df></df></df></Tuv></Tu>");
    }
    myStream.Write("</Raw></Body></TRADOStag>");
    myStream.Close();
    myStream1.Close();
    请帮我看看,到底哪里错了?
      

  5.   

    有时,而且有时候一天都不出毛病,有时候一天出好几次毛病,根本没有什么规律,不过大多自动回车都是
    *************************
    </df></df></df></Tuv></Tu>
    这样,可是我明明让</df></df></df></Tuv></Tu>和****************在一行的!