.net - C# StreamWriter writing over a current text file -
i have text file next text inside:
[username][0]
i have opened file using streamwriter , want alter 0
1
using streamwriter.write
method. how can this?
if know exact byte position of character(s) want overwrite can this:
using (var author = new streamwriter(filepath)) { writer.basestream.seek(bytepos, seekorigin.begin); writer.write('1'); }
if don't know exact byte position this:
using (var file = new filestream(filepath, filemode.open)) using (var reader = new streamreader(file)) using (var author = new streamwriter(file)) { var openbracketcount = 0; // maintain reading characters until sec open bracket found. { var ch = convert.tochar(reader.read()); if (ch == '[') { openbracketcount++; } } while (openbracketcount < 2); writer.write('1'); }
c# .net
No comments:
Post a Comment