Eliminar caracteres de nueva línea de InputStream
Me gusta eliminar todos los caracteres de nueva línea (tanto para \ n como para \ r \ n) de unajava.io.InputStream
, al leer un archivo, el método correspondiente se ve así:
/**
* @param target {@linkplain File}
* @return {@linkplain InputStream}
* @throws Exception
*/
protected InputStream initInput(final File file)
throws Exception {
InputStream stream = null;
try {
if (file.isDirectory()) {
// throw exception
}
if (!file.exists()) {
// throw another exception
}
//
// *remove newlines here*
//
stream = new FileInputStream(file);
} catch (FileNotFoundException e) {
// throw another exception
}
return stream;
}