inama1
Messages postés10Date d'inscriptionlundi 26 mars 2012StatutMembreDernière intervention18 mai 2012
-
15 mai 2012 à 16:03
Utilisateur anonyme -
15 mai 2012 à 21:23
Bonjours,
J'ai réussi à splitter un fichier text
Mon fichier :
ping 172.22.152.60
Type escape sequence to abort.
Sending 5, 100-byte ICMP Echos to 172.22.152.60, timeout is 2 seconds:
!!!!!
Success rate is 100 percent (5/5), round-trip min/avg/max = 1/1/1 ms
DCN_SW_TUN9000_SRV#
Mais je veux maintenant afficher le champ qui se trouve après le mot : "percent" (aprés tester l'existance du mot "percent")
Merci pour votre aide et voici mon code :
public class parcing_ping {
public static void main(String[] args) {
File file = new File("C:\\ping1.txt");
FileInputStream fis = null;
BufferedInputStream bis = null;
DataInputStream dis = null;
try {
fis = new FileInputStream(file);
bis = new BufferedInputStream(fis);
dis = new DataInputStream(bis);
D'après ton exemple de fichier,
Si afficher le champ qui se trouve après le mot : "percent" c'est afficher l'item suivant:
remplace le code
for (String t :tokens)
{
if((t.compareTo("percent")==0) )
System.out.println(t);}
[/code
par
[code=java]
for(int i = 0; i <tokens.length; i++)
{
if(tokens[i].equals("percent"))
System.out.println("L'item suivant 'percent' est " + tokens[i+1]);
}