Can someone explain me why I get: java.lang.StringIndexOutOfBoundsException: String index out of range: 5
File file = new File("file.txt");
BufferedWriter writer = null;
Date date;
SimpleDateFormat dt = new SimpleDateFormat("yyyy-MM-dd");
try { writer = new BufferedWriter(new FileWriter(file));
writer.write(" ",0,1);
writer.write("FICH", 1, 4);
writer.write("1234", 5, 4);
writer.close();
System.err.println(writer.toString());
}
catch (IOException ex) {
Logger.getLogger(FicheroTdALogic.class.getName()).log(Level.SEVERE, null, ex);
}
finally {
try {writer.close();} catch (Exception ex) {}
}