I am using split()
to tokenize a String separated with *
following this format:
name*lastName*ID*school*age
%
name*lastName*ID*school*age
%
name*lastName*ID*school*age
I'm reading this from a file named "entrada.al" using this code:
static void leer() {
try {
String ruta="entrada.al";
File myFile = new File (ruta);
FileReader fileReader = new FileReader(myFile);
BufferedReader reader = new BufferedReader(fileReader);
String line = null;
while ((line=reader.readLine())!=null){
if (!(line.equals("%"))){
String [] separado = line.split("*"); //SPLIT CALL
names.add(separado[0]);
lastNames.add(separado[1]);
ids.add(separado[2]);
ages.add(separado[3]);
}
}
reader.close();
}
And I'm getting this exception:
Exception in thread "main" java.util.regex.PatternSyntaxException: Dangling meta character '*' near index 0
*
My guess is that the lack of a *
after age on the original text file is causing this. How do I get around it?