Sunday, March 02, 2003

CodeBit; How Can I Improve the I/O Speed for System.out.println Using Java?

Normally, the System.out print stream has a buffer size of 128 and flushes the buffer whenever a newline character is encountered. The following four lines of java change the buffer size to 1024 and doesn't flush the buffer for newline characters.

FileOutputStream fdout = new FileOutputStream(FileDescriptor.out);
BufferedOutputStream bos = new BufferedOutputStream(fdout, 1024);
PrintStream ps = new PrintStream(bos, false);
System.setOut(ps);
Post a Comment