RDV+DIAL chat illimit� dans ta r�g!
no save
Assistance
Achat
News

Forum | programmation
[java] récupération de fichier texte
flora806, le ven. 23 mars 2007 à 14:11:13
salut à tous
j'espère que qqu pourrait m'aider :)
j'ai utilisé le code ci-dessous pour un récupérer un fichier texte en java. ce fichier contient des string + int

ce fichier se présente comme ça:
Id|age|sexe|profession|CodePostal

Mais en fait quand j'exécute ça, ça me donne rien en output et la démo ne marche pas.
je ne sais pas c dû à quoi :(
est-ce que qqu aurait une idée?

Merci.
Flora
********

import java.io.BufferedReader;
import java.io.FileNotFoundException;
import java.io.FileReader;
import java.io.IOException;
import java.util.ArrayList;
import java.util.List;
import java.util.StringTokenizer;
import java.io.FileInputStream;
import java.io.InputStreamReader;
import java.io.RandomAccessFile;
import java.io.Reader;
import java.util.Vector;

public class DemogData {
private String filePath;
private String [][] data;

public DemogData(String filePath) throws IOException {
super();
this.filePath = filePath;
parseFile();
}

private void parseFile() throws IOException {
BufferedReader reader = new BufferedReader(new FileReader(filePath));

String line = null;
List<String> items = new ArrayList<String>();
StringTokenizer splitter;
while ((line = reader.readLine()) != null) {
items.add(line);
}
data = new String [items.size()][5];
int counter = 0;
for (String item : items) {
splitter = new StringTokenizer(item, "|");
int nv = splitter.countTokens() ;

counter++;
}


}



public String[] getuList(String occupation) {
String[] uList = new String[0];
for (String[] dataLine : data) {
if (dataLine[3] == occupation) {
String[] newList = new String[uList.length + 3];
int counter = 0;
for (String entry : uList) {
newList[counter] = entry;
counter++;
}
newList[counter] = dataLine[0];
uList = newList;
}
}
return uList;
}

public static void main(String[] args) {
try {
DemogData demo = new DemogData("C:/u.txt");
String occupation = "student";
System.out.print("utilisateurs ayant profession" + " " + occupation + ": ");
for (String i : demo.getuList(occupation)){
System.out.println(i + " ");
}

} catch (IOException e) {
e.printStackTrace();
}
}

}

************* Configuration: Windows XP
Internet Explorer 6.0
Version Web
Réalisé par RedShift
no save