Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- using System;
- using System.Collections.Generic;
- using System.Linq;
- using System.Text;
- using System.IO;
- using System.Runtime.Serialization.Formatters.Binary;
- namespace HCI_Projekat.klase
- {
- class Zivotinje
- {
- private static List<ZivotinjskeVrste> zivotinjskeVrste = new List<ZivotinjskeVrste>();
- private readonly string datoteka;
- private static Zivotinje instance;
- private Zivotinje()
- {
- datoteka = Path.Combine(AppDomain.CurrentDomain.BaseDirectory, "zivotinjskeVrste.dat");
- LoadFile();
- }
- public static Zivotinje getInstance()
- {
- if (instance == null)
- instance = new Zivotinje();
- return instance;
- }
- public List<ZivotinjskeVrste> getZivotinjskeVrste()
- {
- return zivotinjskeVrste;
- }
- public void LoadFile()
- {
- BinaryFormatter formatter = new BinaryFormatter();
- FileStream stream = null;
- if (File.Exists(datoteka))
- {
- try
- {
- stream = File.Open(datoteka, FileMode.Open);
- zivotinjskeVrste = (List<ZivotinjskeVrste>)formatter.Deserialize(stream);
- }
- catch
- {
- //
- }
- finally
- {
- if (stream != null)
- stream.Dispose();
- }
- }
- else
- zivotinjskeVrste = new List<ZivotinjskeVrste>();
- }
- public void SaveFile()
- {
- BinaryFormatter formatter = new BinaryFormatter();
- FileStream stream = null;
- try
- {
- stream = File.Open(datoteka, FileMode.OpenOrCreate);
- formatter.Serialize(stream, zivotinjskeVrste);
- }
- catch
- {
- //
- }
- finally
- {
- if (stream != null)
- stream.Dispose();
- }
- }
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement