Created
May 11, 2012 18:31
-
-
Save presci/2661552 to your computer and use it in GitHub Desktop.
Buffered Writer in java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
package com.etrade.neo.util; | |
import java.io.StringWriter; | |
public class TestWriter { | |
public static void main(String[] args) { | |
String source = "Now is the time for all good men\\n" | |
+ " to come to the aid of their country\\n" | |
+ " and pay their due taxes."; | |
char buffer[] = new char[source.length()]; | |
source.getChars(0, source.length(), buffer, 0); | |
StringWriter writer = new StringWriter(); | |
int off = 0; | |
int len = 4; | |
while (true) { | |
if (buffer.length > (off + len)) { | |
writer.write(buffer, off, len); | |
} else { | |
len = buffer.length - off; | |
writer.write(buffer, off, len); | |
break; | |
} | |
off = off + 4; | |
} | |
System.out.println(writer.getBuffer().toString()); | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment