02-12-2012, 11:37 PM
static LinkedList<People> create(String nameFile)
throws IOException
{ LinkedList<People> list = new LinkedList<People>();
boolean Fileexists = true ;
FileReader fi = null;
try {
fi = new FileReader (nameFile) ;
}
catch ( java.io.FileNotFoundException erreur) {
System.out.println("Probleme d'ouvrir le fichier " +
nameFile);
Fileexists = false ;
}
if (Fileexists) {
BufferedReader enter = new BufferedReader(fi);
boolean endFile = false ;
while ( !endFile ) {
String aLine = enter.readLine();
if (aLine == null)
endFile = true ;
else {
String name = aLine.substring(0, 10);
char sex = aLine.charAt(30);
double height = Double.parseDouble(aLine.substring(37, 41));
double weight = Double.parseDouble(aLine.substring(51, 56).trim());
int number = Integer.parseInt(aLine.substring(64));
liste.add(new People(name, sex, height, weight, number));
}
}
enter.close();
}
return list;
}
throws IOException
{ LinkedList<People> list = new LinkedList<People>();
boolean Fileexists = true ;
FileReader fi = null;
try {
fi = new FileReader (nameFile) ;
}
catch ( java.io.FileNotFoundException erreur) {
System.out.println("Probleme d'ouvrir le fichier " +
nameFile);
Fileexists = false ;
}
if (Fileexists) {
BufferedReader enter = new BufferedReader(fi);
boolean endFile = false ;
while ( !endFile ) {
String aLine = enter.readLine();
if (aLine == null)
endFile = true ;
else {
String name = aLine.substring(0, 10);
char sex = aLine.charAt(30);
double height = Double.parseDouble(aLine.substring(37, 41));
double weight = Double.parseDouble(aLine.substring(51, 56).trim());
int number = Integer.parseInt(aLine.substring(64));
liste.add(new People(name, sex, height, weight, number));
}
}
enter.close();
}
return list;
}