. : BufferedWriter ?
jdk
, writer.write()? , flush ?
. , write(String s), : write(str, 0, str.length()); openJDK:
218 public void write(String s, int off, int len) throws IOException {
219 synchronized (lock) {
220 ensureOpen();
221
222 int b = off, t = off + len;
223 while (b < t) {
224 int d = min(nChars - nextChar, t - b);
225 s.getChars(b, b + d, cb, nextChar);
226 b += d;
227 nextChar += d;
228 if (nextChar >= nChars)
229 flushBuffer();
230 }
231 }
232 }
233
118 /**
119 * Flushes the output buffer to the underlying character stream, without
120 * flushing the stream itself. This method is non-private only so that it
121 * may be invoked by PrintStream.
122 */
123 void flushBuffer() throws IOException {
124 synchronized (lock) {
125 ensureOpen();
126 if (nextChar == 0)
127 return;
128 out.write(cb, 0, nextChar);
129 nextChar = 0;
130 }
131 }
, . if (nextChar >= nChars), ( private static int defaultCharBufferSize = 8192;, "wrapping".
( java, Java IO - Decorator. write(char[] chars, int i, int i1).)
while , . while, BufferedWriter?
The cost of IO is VERY expensive. If you donβt need to look at the output on the fly (for example, look at the log anytime with the latest updates), you should let the performance increase automatically.
source
share