C
C#3y ago
Rohan

❔ File IO Question.

Is there anyway to empty a json file? I know you can delete the file but is there anyway to empty all the json in the file instead of deleting it? Thanks
9 Replies
Angius
Angius3y ago
Just write an empty string
mtreit
mtreit3y ago
What @Angius said...but why?
ChucklesTheBeard
also take a look at the various FileMode options; Truncate is probably of interest
Rohan
RohanOP3y ago
Like I wanna edit a json file Using Newtonsoft I figured out how to edit the jsonString Now how do u edit the actual file Thats my question
Angius
Angius3y ago
Serialize the object to a string Save string in a file await File.WriteAllTextAsync("filename.json", theJsonString) for example
Rohan
RohanOP3y ago
Oh..if u give WriteAllText a filename that exists, does it overwrite it?
Angius
Angius3y ago
Yeah
Rohan
RohanOP3y ago
Ohhhhhhh Im stupid Thanks
Accord
Accord3y ago
Was this issue resolved? If so, run /close - otherwise I will mark this as stale and this post will be archived until there is new activity.

Did you find this page helpful?