java versus hardtek
Messages postés18Date d'inscriptionmardi 7 septembre 2004StatutMembreDernière intervention17 juillet 2007
-
17 sept. 2004 à 02:25
HFanny
Messages postés699Date d'inscriptionmercredi 19 février 2003StatutMembreDernière intervention13 mai 2011
-
17 sept. 2004 à 08:53
Je veux lire toutes les lignes de ce fichier.
Mais je ne fait que lire la première ligne. Comment passer au suivantes ?
public int[] recuperer_standard_BUT ()
{
String adresse_du_fichier = System.getProperty("user.dir") + "\\standard_BUT.txt";
int tab_BUT[] = new int[32];
try
{
FileReader fr = new FileReader(adresse_du_fichier);
BufferedReader br = new BufferedReader(fr);
String texte = "";
for(int i = 0; i<32; i++)
{
texte = texte + br.readLine();
int j = Integer.valueOf(texte).intValue();
tab_BUT[i] = j;
}
HFanny
Messages postés699Date d'inscriptionmercredi 19 février 2003StatutMembreDernière intervention13 mai 201120 17 sept. 2004 à 08:53
Salut,
pour lire toutes les lignes d'un fichier une par une il faut boucler sur readLine() jusqu'à temps que ce que le résultat de readLine soit égal à null :
ligne = br.readLine();
i = 0;
while (ligne != null)
{
texte = texte + ligne;
int j = Integer.valueOf(texte).intValue;
tab_BUT[i] = j;
ligne = dis.readLine();
i++;
}
ou bien :
while( (ligne=br.readLine())!=null)
{
texte = texte + ligne;
int j = Integer.valueOf(texte).intValue;
tab_BUT[i] = j;
ligne = dis.readLine();
i++;
}