Por ahí va la cosa y cuando lo pongas, usa GeShi en modo bash package com.ficheros.foro;
import javax.swing.*;
import java.io.BufferedReader;
import java.io.BufferedWriter;
import java.io.IOException;
import java.nio.charset.Charset;
import java.nio.file.Files;
import java.nio.file.Path;
import java.nio.file.Paths;
import java.time.LocalDate;
import java.util.ArrayList;
import java.util.List;
import java.util.Objects;
import java.util.logging.Logger;
/**
* autor @rub´n
* https://foro.elhacker.net/java/ayuda_con_lectura_y_escritura_en_ficheros_java-t495247.0.html
*/
public class RelPerCen {
private static final Logger LOGGER = Logger.getLogger(RelPerCen.class.getSimpleName());
private static final String MATCHES
= "| |"; private static final String REEMPLAZO
= "|" + LocalDate.
MIN.
toString() + "|"; private static final String REPLACE
= "[\\]\\[]";
public static List
<String
> leerFichero
(final String nombre
) { final List<String> list = new ArrayList<>();
LOGGER.info("Raiz de proyecto" + Paths.get(".").toAbsolutePath().toString());
try (final BufferedReader br
= Files.
newBufferedReader(Paths.
get(nombre
), Charset.
defaultCharset())) { LOGGER.info("Leyendo el fichero de empleados\n");
final StringBuilder sb = new StringBuilder();
while (Objects.nonNull(line = br.readLine())) {
if (!line.contains(MATCHES)) {
final String s
= line.
replace(MATCHES, REEMPLAZO
); sb.append(s)
.
append(System.
lineSeparator()); }
if (line.contains(MATCHES)) {
final String s
= line.
replace(MATCHES, REEMPLAZO
); sb.append(s)
.
append(System.
lineSeparator()); }
}
/**
* Despues del while
*/
list.add(sb.toString());
JOptionPane.
showMessageDialog(null,
"No existe el fichero"); LOGGER.severe("No existe el fichero " + ex.toString());
}
return list;
}
public static void escribir
(final List
<String
> empleado,
final String nombreFichero
) { try (final BufferedWriter bw
= Files.
newBufferedWriter(Paths.
get(nombreFichero
))) {
bw.write(empleado.toString()
.replaceAll(REPLACE, ""));
LOGGER.severe("Error al escribir fichero " + ex.toString());
}
}
public static void main
(String...
blablablablabla) { final RelPerCen r = new RelPerCen();
/**
* Leer el fichero completamente
*/
final List<String> ficheroLiedo = r.leerFichero("ficheroEmpleados.txt");
/**
* Crear el fichero con las fechas de cese en LocalDate.MIN
*/
r.escribir(ficheroLiedo, "ficheroEmpleadosConFechaDeCese.txt");
}
}
Salida actual, falta formateoTítulo: PERSONAL DEL CENTRO
Autor: Aplicación Séneca, CONSEJERÍA DE EDUCACIÓN Y DEPORTE, Junta de Andalucía
Fecha de creación: 30/04/19 - 10:01
---------------------------------------+----------------------------------------+-------------------------+-------------+---------+-----------
Empleado/a |Puesto |Fecha de toma de posesión|Fecha de cese|Evaluador|Coordinador
---------------------------------------+----------------------------------------+-------------------------+-------------+---------+-----------
Aldridge Torres, Pérez |Física y Química P.E.S. |01/09/2012 |-999999999-01-01|Sí |No
Álvarez Ortega, María Dolores |Pedagogía Terapeutica Eso |01/09/2005 |-999999999-01-01|No |No
Baquero Reyes, Cristina |Biología y Geología P.E.S. |18/02/2019 |30/04/2019 |No |No
Bermúdez Iñiguez, José Luis |Geografía e Historia P.E.S. |01/09/2018 |30/06/2019 |No |No
Beswick Algarrada, Cristina |Orientación Educativa P.E.S. |01/09/2008 |-999999999-01-01|No |No
Blanco Borrego, Mirian |Física y Química P.E.S. |01/09/2004 |-999999999-01-01|No |Sí
Borrego Alcaide, Miguel Ángel |Lengua Castellana y Literatura P.E.S. |01/09/2018 |30/06/2019 |No |No
Butrón Cobo, Lucía |Administración de Empresas P.E.S. |25/09/2018 |09/03/2019 |No |No