I am doing an exercise in which your goal is to enter a file with File, read it and check with a split if the two words that are between the symbol " | " are equal (letter by letter). I tried to do it with a "charAt" but it does not work out at all.
public class Main {
public static void main(String[] args) throws FileNotFoundException {
File ips = new File("C:\Users\Victor\Desktop\e.txt");
Scanner teclado=null;
String texto="";
try {
teclado=new Scanner(new FileReader(ips));
} catch (FileNotFoundException e) {
e.printStackTrace();
}
while (teclado.hasNextLine()){
texto+=teclado.nextLine() + "\n";
}
String[] separacion = texto.split("\n");
for (int i = 0; i < separacion.length; i++) {
String[] separacion2 = separacion[i].split("\|");
for (int j = 0; j < separacion2.length; j++) {
}
}
teclado.close();
}
}
In the text file I have this:
Hello | hi
Hello | jewel
Hello | Hello
Hello | Hole