but it is not contain new line code.
I working simply that is make data replace tools of text file.
that text file has been edited by Mac or Windows.
Therefore, it is include some new line code.
So, when after replace data if new line code is no previous new line code then confuse where modified by replace data.
Next, I search this problem on the internet.
However, not found that return new line code that readLine of BufferedReader.
So much trouble, I expand to contain new line code from return that readLine of BufferedReader.
Program is simple.
when reading data, if exist \r or \n in data then return value with new line code.
This code is below.
package extension.java.io; import java.io.BufferedReader; import java.io.IOException; import java.io.Reader; public class ExtensionBufferedReader extends BufferedReader { public ExtensionBufferedReader(Reader in) { super(in); } public ExtensionBufferedReader(Reader in, int sz) { super(in, sz); } @Override public String readLine() throws IOException { int num = 0; StringBuffer strBfr = new StringBuffer(); try { while ((num = this.read()) >= 0) { strBfr.append((char) num); switch ((char) num) { case '\r': case '\n': return strBfr.toString(); default: break; } } } catch (IOException e) { throw e; } if (strBfr.length() == 0) { return null; } else { return strBfr.toString(); } } }
No comments:
Post a Comment