posted 12 years ago
Until we know it, we feel bad.
As I had an issue with SFTP/SCP transferred file from UNIX to Windows and found the simple resolution, I would like to share I learn.
Whatever the platform you are using, handling the file which was transferred by SFTP or SCP does not seem to be easy and simple - especially when the next process on Windows PC expects a simple text (DOS in this situation) file format. I tried to see the raw bytes of the records and insert the CR in front of each LF, because UNIX transferred file has LFLF if transferred via SFTP/SCP from UNIX. It did not work, and analyzing how it should work would take your time a lot.
The mistake started with InputStream read!
We should use the simplest file read scheme, FileReader->BufferredReader. This method will read in only the text part of the file with no control characters like CR or LF.
Now, the simplest file write scheme, FileWriter->BufferedWriter, can write only the record's text part. So, paired/coupled/followed BufferredWriter.newLine() is a critical part.
I know ordinary programmer should know this already, but a 20 year IT field player did not know this fact. Anyway, it's fun to know how to handle this.