Rafael M
2014-11-11 21:35:37 UTC
Exception in thread "main" java.lang.ArrayIndexOutOfBoundsException: 1
at hotelf3.HotelF3.cargarHotel(HotelF3.java:111)
este error sucede solo cuando lee palabras con espacio como = "El Salvador"
les dejo el metodo para no hacernos bolas con explicaciones:
public void cargarHotel(){
String[] datos;
String text, text1, text2;
String linea = null; //Para guardar los datos de forma temporal
File hoteles = new File("hoteles.txt");
if (hoteles.exists()) { //Si se ha creado el fichero
try {
Scanner lector = new Scanner(hoteles);
while(lector.hasNext()){
linea = lector.next();
datos = linea.split(",");
text = datos[0];
text1 = datos[1]; //esta es la linea 111
text2 = datos[2];
System.out.println("Pais: "+text);
System.out.println("Nombre: "+text1);
System.out.println("Direccion: "+text2)
}
System.out.println("Hoteles = "+ini.seg.adm.nh.lh.tamano());
} catch (FileNotFoundException ex) {
System.out.println("No se pudo abrir el archivo!"+ex.getMessage());
}
}
}