Advertisement
Guest User

Untitled

a guest
Mar 27th, 2017
39
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.59 KB | None | 0 0
  1. package prueba.de.buscar.dentro.de.un.archivo;
  2.  
  3. import java.io.BufferedReader;
  4. import java.io.FileNotFoundException;
  5. import java.io.FileReader;
  6. import java.io.IOException;
  7. import java.util.Scanner;
  8.  
  9. public class PruebaDeBuscarDentroDeUnArchivo {
  10. /**
  11. * @param args the command line arguments
  12. */
  13. public static void main(String[] args) {
  14. // TODO code application logic here
  15. java.util.Scanner scanner = new Scanner(System.in);
  16. System.out.println("Introduce una cadena de texto a buscar: ");
  17. String request = scanner.next();
  18. try {
  19. final BufferedReader reader = new BufferedReader(new FileReader("C:\Users\ProKode\Downloads\archivo.txt"));
  20. String line = "";
  21. while((line = reader.readLine())!= null) {
  22. if(line.indexOf(";")!= -1){
  23. if (line.split(";")[0].equalsIgnoreCase(request)) {
  24. System.out.println("Se encontro la palabra "+ request);
  25. }
  26. }
  27. }
  28. reader.close();
  29. } catch (FileNotFoundException e) {e.printStackTrace();
  30. } catch (IOException e) {e.printStackTrace();
  31. }
  32. }
  33. }
  34.  
  35. Exception in thread "main" java.lang.ArrayIndexOutOfBoundsException: 0
  36. at prueba.de.buscar.dentro.de.un.archivo.PruebaDeBuscarDentroDeUnArchivo.main(PruebaDeBuscarDentroDeUnArchivo.java:23)
  37. Java Result: 1
  38. BUILD SUCCESSFUL (total time: 10 seconds)
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement