import java.util.*;
import java.io.*;
import java.*;
public class b {
static void lireBddParcs(String nomFichier) throws IOException
{
LinkedHashMap parcMap = new LinkedHashMap<Parc,Collection<Manege>> ();
boolean existeFichier = true;
FileReader fr = null;
try
{
fr = new FileReader (nomFichier);
}
catch(java.io.FileNotFoundException erreur)
{
System.out.println("Probleme rencontree a l'ouverture du fichier" + nomFichier);
existeFichier = false;
}
if (existeFichier)
{
Scanner scan = new Scanner(nomFichier).useDelimiter("\t");
while (scan.hasNextLine())
{
String nom = scan.next();
String ville = scan.next();
String etat = scan.next();
Parc p = new Parc(nom, ville, etat);
parcMap.put(p, null);
}
scan.close();
}
}
public static void main(String[] args) throws IOException
{
lireBddParcs("parcs.txt");
}
}
parc.txt 包含:
Great America Chicago Illinois
Magic mountain Los Ageles Californie
Six Flags over Georgia Atlanta Georgie
Darien Lake Buffalo New York
La Ronde Montreal Quebec
The Great Escape Lake Georges New York
Six Flags New Orleans New Orleans Louisiane
Elitch Gardens Denver Colorado
Six Flags over Texas Arlington Texas
Six Flags New England Springfield Massachusetts
Six Flags America Washington D.C.
Great Adventure Jackson New Jersey
我明白了:
--------------------Configuration: <Default>--------------------
Exception in thread "main" java.util.NoSuchElementException
at java.util.Scanner.throwFor(Scanner.java:907)
at java.util.Scanner.next(Scanner.java:1416)
at b.lireBddParcs(b.java:54)
at b.main(b.java:94)
我一直在尝试修复程序 3 个小时。天哪,我是哑巴。不知道程序有什么问题!