Java tutorial
//package com.java2s; /* This file is part of GALE (Generic Adaptation Language and Engine). GALE is free software: you can redistribute it and/or modify it under the terms of the GNU Lesser General Public License as published by the Free Software Foundation, either version 3 of the License, or (at your option) any later version. GALE is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public License for more details. You should have received a copy of the GNU Lesser General Public License along with GALE. If not, see <http://www.gnu.org/licenses/>. */ import java.io.File; import java.io.FileReader; import java.io.IOException; import java.io.LineNumberReader; import java.util.Hashtable; public class Main { /** * Loads an index (Hashtable) from a file. * * @param root_ * The file where the index is stored in. * @return The indextable. * @exception IOException * If an internal error prevents the file from being read. */ public static Hashtable loadIndex(File root_, String name) throws IOException { File indexfile = new File(root_, name); Hashtable index = new Hashtable(); if (indexfile.exists()) { LineNumberReader in = new LineNumberReader(new FileReader(indexfile)); while (in.ready()) index.put(in.readLine(), new Long(in.readLine())); in.close(); } return index; } /** * Loads an index (Hashtable) from a file. * * @param root_ * The file where the index is stored in. * @return The indextable. * @exception IOException * If an internal error prevents the file from being read. */ public static Hashtable loadIndex(File root_) throws IOException { return loadIndex(root_, "index"); } }