Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- package prueba.de.buscar.dentro.de.un.archivo;
- import java.io.BufferedReader;
- import java.io.FileNotFoundException;
- import java.io.FileReader;
- import java.io.IOException;
- import java.util.Scanner;
- public class PruebaDeBuscarDentroDeUnArchivo {
- /**
- * @param args the command line arguments
- */
- public static void main(String[] args) {
- // TODO code application logic here
- java.util.Scanner scanner = new Scanner(System.in);
- System.out.println("Introduce una cadena de texto a buscar: ");
- String request = scanner.next();
- try {
- final BufferedReader reader = new BufferedReader(new FileReader("C:\Users\ProKode\Downloads\archivo.txt"));
- String line = "";
- while((line = reader.readLine())!= null) {
- if(line.indexOf(";")!= -1){
- if (line.split(";")[0].equalsIgnoreCase(request)) {
- System.out.println("Se encontro la palabra "+ request);
- }
- }
- }
- reader.close();
- } catch (FileNotFoundException e) {e.printStackTrace();
- } catch (IOException e) {e.printStackTrace();
- }
- }
- }
- Exception in thread "main" java.lang.ArrayIndexOutOfBoundsException: 0
- at prueba.de.buscar.dentro.de.un.archivo.PruebaDeBuscarDentroDeUnArchivo.main(PruebaDeBuscarDentroDeUnArchivo.java:23)
- Java Result: 1
- BUILD SUCCESSFUL (total time: 10 seconds)
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement