Free cookie consent management tool by TermsFeed Policy Generator

Changeset 687


Ignore:
Timestamp:
10/19/08 00:27:45 (16 years ago)
Author:
gkronber
Message:

fixed #312 (File is not closed when open fails (with an Exception))

File:
1 edited

Legend:

Unmodified
Added
Removed
  • trunk/sources/HeuristicLab.Core/PersistenceManager.cs

    r402 r687  
    6565    }
    6666    public static void Save(IStorable instance, string filename) {
    67       FileStream stream = File.Create(filename);
    68       Save(instance, stream);
    69       stream.Close();
     67      using(FileStream stream = File.Create(filename)) {
     68        Save(instance, stream);
     69        stream.Close();
     70      }
    7071    }
    7172    public static void Save(IStorable instance, Stream stream) {
     
    7677    }
    7778    public static IStorable Load(string filename) {
    78       FileStream stream = File.OpenRead(filename);
    79       IStorable storable = Load(stream);
    80       stream.Close();
    81       return storable;
     79      using(FileStream stream = File.OpenRead(filename)) {
     80        IStorable storable = Load(stream);
     81        stream.Close();
     82        return storable;
     83      }
    8284    }
    8385    public static IStorable Load(Stream stream) {
Note: See TracChangeset for help on using the changeset viewer.