je l'ai écrit ci-dessous le code pour lire un fichier:différence dans le fichier de lecture lors de l'utilisation d'une variable chaîne
package com.test.application;
import java.io.*;
import java.io.IOException;
public class FileRead {
public static void main(String[] args) {
try{
File file=new File("Hello.txt");
FileReader fileReader=new FileReader(file);
BufferedReader reader=new BufferedReader(fileReader);
/*String line=null;
while((line = reader.readLine())!=null){
System.out.println(line);
} */
System.out.println("This is using no string variable!!!");
while(reader.readLine()!=null){
System.out.println(reader.readLine());
}
reader.close();
}
catch(IOException e){
}
}
}
mon fichier texte est:
What is Lorem Ipsum?
Lorem Ipsum is simply dummy text of the printing and typesetting
industry.
Lorem Ipsum has been the industry's standard dummy text ever since the
1500s, when an unknown printer took a galley of type and scrambled it
to make a type specimen book.
It has survived not only five centuries, but also the leap into
electronic typesetting, remaining essentially unchanged.
It was popularised in the 1960s with the release of Letraset sheets
containing Lorem Ipsum passages, and more recently with desktop
publishing software like Aldus PageMaker including versions of Lorem
Ipsum.
Ma question ici est quand je me sers d'un variable de chaîne à lire à partir du fichier, ima obtenir tout le contenu du fichier, à savoir:
String line=null;
while((line = reader.readLine())!=null){
System.out.println(line);
}
mais quand je l'ai utilisé le code ci-dessous un extrait pour lire le fichier, quelques lignes où il a été ignoré et l'intégralité du fichier n'a pas été lue.
while(reader.readLine()!=null){
System.out.println(reader.readLine());
}
Quelqu'un peut-il expliquer pourquoi cela se produit.
Merci, c'était ça, j'aurais dû remarquer. –