package Yamanelow; import java.io.FileInputStream; import java.io.InputStreamReader; import java.io.BufferedReader; import java.io.IOException; import java.io.InputStream; /** * @author Yann * */ public class YamanelowExo2 { public static void main (String[] args) { String _file = "C:\\Users\\Yann\\Documents\\Eclipse Workspace\\Tests\\Yamanelow\\YamanelowExo2.txt"; String _word = "Yamaneko"; int _count = 0; int _line = 1; try { InputStream ips=new FileInputStream(_file); InputStreamReader ipsr=new InputStreamReader(ips); BufferedReader br=new BufferedReader(ipsr); String ligne; while ((ligne=br.readLine())!=null) { int i = ligne.indexOf(_word); int c = 0; while (i > -1) { _count++; c++; ligne = ligne.substring(i + _word.length()); i = ligne.indexOf(_word); } if (c > 0) System.out.println(c + " Trouves a la ligne " + _line); _line++; } br.close(); System.out.println(_count + " objets trouve ! Stupide chat :p"); } catch (IOException e) { // Exception déclenchée si un problème survient pendant l'accès au fichier System.out.println (e); } } }