Thread Rating:
  • 0 Vote(s) - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
Can you rewrite this method without using LinkedList?
#1
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;
}
Reply


Messages In This Thread
Can you rewrite this method without using LinkedList? - by wholegrain - 02-12-2012, 11:37 PM

Forum Jump:


Users browsing this thread: 1 Guest(s)