cs_peker
Messages postés5Date d'inscriptionlundi 5 novembre 2007StatutMembreDernière intervention 4 mai 2008
-
3 mai 2008 à 21:55
sheorogath
Messages postés2448Date d'inscriptionsamedi 21 février 2004StatutModérateurDernière intervention29 janvier 2010
-
5 mai 2008 à 09:17
Bonjour,
Je lis un fichier texte dans mon programme java.
Ce fichier est composé de plusieurs lignes.
Ex :
a
b
Il me dit que j'ai quatre caractères car il compte les sauts de pages !
Je souhaite récuperer chaque ligne du fichier dans un tableau sans les retour chariots.
while (i < longueurFichier) {
if (car.equals("[\n\r]")){
System.out.println("car : <"+ car+">");
} else { nomLangage[j] = car; j++; }
i= i+ 1;
}
Comment tester le retour chariot en Java ? La mon exemple ne marche pas.
J'ai essayé avec "\n\r", "13".
Je cherche depuis un long moment sans succès.
cs_peker
Messages postés5Date d'inscriptionlundi 5 novembre 2007StatutMembreDernière intervention 4 mai 2008 3 mai 2008 à 22:13
Ca fait un moment que je cherche.
J'arrive à lire le fichier,
c'est pour exploiter les données du fichier, il me prend en compte le retour chariot.
J'ai fais plein de recherche sur internet, quand je tape "lire ligne à ligne en java", je retombe sur mes recherches !
Madvin
Messages postés123Date d'inscriptionmardi 5 août 2003StatutMembreDernière intervention26 août 20123 4 mai 2008 à 02:29
Ben t'as mal cherché !! C'est une fonctionnalité très fréquemment demandée... Je te donne juste ça, tu n'as plus qu'à t'en servir :
Extrait Javadoc :
java.io
Class BufferedReader
readLine
public StringreadLine()
throws IOExceptionRead a line of text. A line is considered to be terminated by any one
of a line feed ('\n'), a carriage return ('\r'), or a carriage return
followed immediately by a linefeed.
<dl> * Returns: : <dd>A String containing the contents of the line, not including
any line-termination characters, or null if the end of the
stream has been reached
* Throws: : <dd>