Formular una preguntaFormular una pregunta
 

RespondidaStreamWriter and NewLine

  • viernes, 06 de noviembre de 2009 17:45swingme Medallas del usuarioMedallas del usuarioMedallas del usuarioMedallas del usuarioMedallas del usuario
     Tiene código
    hallo everybody,

    I want to create a text file by writing a single line at a time and use the following method.
    FileStream fs = new System.IO.FileStream(file, System.IO.FileMode.Create,             System.IO.FileAccess.Write, System.IO.FileShare.None);
    
    StreamWriter sw = new System.IO.StreamWriter(fs, System.Text.Encoding.Default);
    
    sw.WriteLine("Line 1");
    
    sw.Close();
    
    

    Problem is that the text file contains two lines where the second line is empty. StreamWriter advances to next line after writing a line is the reason i think....

    How can i create the text file without an empty line at the end of the file. ?

    I don't want to use StringBuilder or any thing like that to create the text and write the whole content all together to the text file.

    How can i do it ? I am using dot net 2.0

    Thanks for any help in advance :-)

    regards
    swingme

Respuestas

Todas las respuestas