diff --git a/JSON.cs b/JSON.cs index 8faa75c..59ace9a 100644 --- a/JSON.cs +++ b/JSON.cs @@ -127,9 +127,11 @@ namespace sharp.json } public void WriteTo(String filename,bool pretty) { - FileStream fs = new FileStream(filename, FileMode.Create); - WriteTo(fs,pretty); - fs.Close(); + using (FileStream fs = new FileStream(filename, FileMode.Create)) + { + WriteTo(fs, pretty); + fs.Close(); + } } public static JSON ReadFrom(string filename) @@ -161,6 +163,10 @@ namespace sharp.json } catch (FileNotFoundException e){ return defaultValue; } + if (source.Equals("")) + { + return defaultValue; + } return parser.Parse(source); }