1

I tried to read content and write it to file. The code run on server when the server is on linux I don't have any problem. when I run it on windows for any string in the end I got another space How I can fix it ?

  public static void readFile(InputStream inputStream, OutputStream outputStream, boolean closeIn, boolean closeOut) throws IOException {
    byte[] buffer = new byte[4096];
    int read = 0;
    try {
        while ((read = inputStream.read(buffer)) != -1)
            outputStream.write(buffer, 0, read);
    } finally {
        //close input and output
    }
}
user1365697
  • 5,819
  • 15
  • 60
  • 96
  • maybe it's a problem with windows and linux having different line newline characters/character sequences: \n vs \r\n btw: without having a look at your input/output one can only guess what seems to be your problem... – xmoex Jan 27 '16 at 12:58
  • 1
    Open your file with an hexadecimal editor and check wich is the last character, probably is not a standard space. – Davide Lorenzo MARINO Jan 27 '16 at 13:05
  • I guess you wrtte it is \r\n in windows and \n linux but how I can fix it ? – user1365697 Jan 27 '16 at 13:08
  • I checked it in the console the last character is \r\n in windows case – user1365697 Jan 27 '16 at 13:09
  • Do I need to change the write and read in this case ? meaning that windows and Linux I got different string – user1365697 Jan 27 '16 at 13:11
  • 1
    @user1365697 Have a look at this: http://stackoverflow.com/questions/207947/how-do-i-get-a-platform-dependent-new-line-character – Chris Wohlert Jan 27 '16 at 13:25
  • The code you have shown does a binary copy of the input stream. No line end conversion is happening. You should get identical results on Linux and Windows. – Henry Jan 27 '16 at 13:28

0 Answers0