public int read() throws IOException { int c = file.read(); if (c != '\r') return c; if (file.available() > 0) { c = file.read(); if (c != -1 && c != '\n') file.unread(c); } return '\n'; }
public String read(int n) throws IOException { String s = this.file.read(n); int index = s.indexOf('\r'); if (index < 0) return s; StringBuffer buf = new StringBuffer(); int start = 0; int end = s.length(); do { buf.append(s.substring(start, index)); buf.append('\n'); start = index + 1; if (start < end && s.charAt(start) == '\n') start++; index = s.indexOf('\r', start); } while (index >= 0); buf.append(s.substring(start)); if (s.endsWith("\r") && file.available() > 0) { int c = file.read(); if (c != -1 && c != '\n') file.unread(c); } return buf.toString(); }