c# - understanding filestream -


right i'm writing file disk using approach

using (filestream filestream = new filestream(fileone, filemode.create)) {     using (streamwriter streamw = new streamwriter(filestream))     {        streamw .write("blah");        streamw.close();     }     filestream .close(); } 

how can write more files, example filetwo inside using statement?

how can write more files, example filetwo inside using statement?

you'd need open different stream. each filestream write single file. it's not clear whether want write 2 files at time, or write 1 file after another. in latter case, might want loop. example:

foreach (string file in files) {     // note: file.createtext simpler creating filestream     // wrapping in streamwriter     using (textwriter writer in file.createtext(file))     {         ...     } } 

note don't need close calls - fact you've got appropriate using statements means dispose called automatically, equivalent close.


Comments

Popular posts from this blog

monitor web browser programmatically in Android? -

ios - iPhone/iPad different view orientations in different views , and apple approval process -

Shrink a YouTube video to responsive width -