MSDN > Home page del forum > Visual C# General > StreamWriter and NewLine
Formula una domandaFormula una domanda
 

Con rispostaStreamWriter and NewLine

  • venerdì 6 novembre 2009 17.45swingme Medaglie utenteMedaglie utenteMedaglie utenteMedaglie utenteMedaglie utente
     Contiene codice
    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

Risposte

Tutte le risposte