Removendo caracteres newline do InputStream
Eu gosto de remover todos os caracteres de nova linha (para \ n e \ r \ n) de umjava.io.InputStream
, enquanto lê um arquivo, o método correspondente se parece com isto:
/**
* @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;
}