Reading newline char in java -


i appending , streaming bunch of files , want trim header line after first file. on windows following java code adds blank line , see garbled chars in notepad++. fixes/suggestions? thank you.

    private int updateheader(byte[] buffer) throws unsupportedencodingexception {       if (first) {         return buffer.length;       }       string s, s2;       s = new string(buffer, "utf-8");       int k = s.indexof(system.getproperty("line.separator"), 0);       s2 = s.substring(k + 1);       byte[] buffer2 = s2.getbytes("utf-8");       system.arraycopy(buffer2, 0, buffer, 0, buffer2.length);       return buffer2.length;    } 

my guess should like:

... string separator = system.getproperty("line.separator"); int k = s.indexof(separator, 0); s2 = s.substring(k + separator.length()); s2 = s2.trim(); ... 

windows line separators more 1 character long (cr + lf) vs. unix lf based on this. also, might tricky if move files across platforms.

edit i'm not sure you're seeing since don't quite have files, try trimming substring if see funky characters. sure files of right encoding , you're reading them properly?


Comments

Popular posts from this blog

blackberry 10 - how to add multiple markers on the google map just by url? -

php - guestbook returning database data to flash -

delphi - Dynamic file type icon -