ByteArrayOutputStream/InputStream losing newline characters on S3 Import

感情迁移 提交于 2019-12-10 12:18:06

问题


I have the following code (pseudo code-ish)...

ByteArrayOutputStream output = new ByteArrayOutputStream();
output.write("something\n".getBytes());
output.write("something\n".getBytes());

ByteArrayOutputStream input = new ByteArrayInputStream(output.getBytes());
s3.putStream(input);

Then when I get the file from s3 it looks like this: somethingsomething.

The newlines are gone!! I can't figure out why that is happening and internet searches have not been helpful. Does anyone have any ideas?


回答1:


It is common problem with *NIX vs Windows files.

Try : "\r\n" instead of "\n"

ByteArrayOutputStream output = new ByteArrayOutputStream();
output.write("something\r\n"".getBytes());
output.write("something\r\n"".getBytes());

ByteArrayOutputStream input = new ByteArrayInputStream(output.getBytes());
s3.putStream(input);


来源:https://stackoverflow.com/questions/20646586/bytearrayoutputstream-inputstream-losing-newline-characters-on-s3-import

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!