public HighscoreStore(String filename) throws IOException, InvalidHighscoreDataException {

		datafile = new File(filename);
		if (datafile.isDirectory()) {
			if (filename.charAt(filename.length()-1) != '\\' &&
				filename.charAt(filename.length()-1) != '/' ) {
				filename += File.separator;
			}
			filename += "highscores.dat";
			datafile = new File(filename);
		}
		
		if (datafile.isFile()) {
			ObjectInputStream data = null;
			try {
				data = new ObjectInputStream(new FileInputStream(datafile));;
				maxCapacity = data.readInt();
				titles = (String[]) data.readObject();
				highscorelist = (LinkedList<IHighscoreEntry>) data.readObject();
			} catch (ClassNotFoundException e) {
				throw new InvalidHighscoreDataException(e);
			} catch (EOFException e) {
				// do nothing
			} catch (Exception e) { // if casting fails
				throw new InvalidHighscoreDataException(e);
			} finally {
				//the stream should be closed, also if a casting fails:
				if (data != null) {
					//caller has to handle IOExceptions of close
					// (IOExceptions of save he has to handle, too)
					data.close();
				}
			}
		}
		
		save(); // make sure file can be written, create if necessary
		// if something locks the file after construction, saving will
		// fail, printing a stacktrace.
	}