StreamWriter StreamReader
程序员文章站
2022-04-15 08:17:45
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(); } } }