c# - How to write text to a file in Windows Phone 8? -
i found example of how write data file in windows phone 8:
https://stackoverflow.com/a/15625701/181771
public async task writedatatofileasync(string filename, string content) { byte[] data = encoding.unicode.getbytes(content); var folder = applicationdata.current.localfolder; var file = await folder.createfileasync(filename, creationcollisionoption.replaceexisting); using (var s = await file.openstreamforwriteasync()) { await s.writeasync(data, 0, data.length); } }
this works, text encoded. i'm attempting write json file i'd save raw text.
what need accomplish this?
use streamwriter
automatically deal encoding.
public async task writedatatofileasync(string filename, string content) { var folder = applicationdata.current.localfolder; var file = await folder.createfileasync(filename, creationcollisionoption.replaceexisting); using (var s = await file.openstreamforwriteasync()) { using (var writer = new streamwriter(s)) { await writer.writeasync(content); } } }
Comments
Post a Comment