StreamWriter StreamReader
程序员文章站
2022-07-02 12:46:25
private void WriteLoginJsonData(object jsonData) { using (FileStream writerFileStream = new FileStream(JsonDataFile, FileMode.OpenOrCreate)) { using..... ......
private void writeloginjsondata(object jsondata) { using (filestream writerfilestream = new filestream(jsondatafile, filemode.openorcreate)) { using (streamwriter writerstream = new streamwriter(writerfilestream, encoding.utf8)) { writerfilestream.setlength(0); string logindatajson = jsonconvert.serializeobject(jsondata, formatting.indented); writerstream.writeline(logindatajson); writerstream.close(); } writerfilestream.close(); } }
private void readloginjsondata() { if (file.exists(jsondatafile)) { using (filestream readerfilestream = new filestream(jsondatafile, filemode.open, fileaccess.read)) { using (streamreader readerstream = new streamreader(readerfilestream, encoding.utf8)) { string jsoncontent= readerstream.readtoend(); if (!string.isnullorwhitespace(jsoncontent)) { console.writeline(jsoncontent); } readerstream.close(); } readerfilestream.close(); } } }
上一篇: golang之range用法
下一篇: 深入理解JVM内存分配策略