File tree Expand file tree Collapse file tree 2 files changed +40
-0
lines changed
main/java/cn/byhieg/iotutorial/bytestreamio
test/java/cn/byhieg/iotutorialtest Expand file tree Collapse file tree 2 files changed +40
-0
lines changed Original file line number Diff line number Diff line change 1+ package cn .byhieg .iotutorial .bytestreamio ;
2+
3+ import java .io .BufferedOutputStream ;
4+ import java .io .File ;
5+ import java .io .FileOutputStream ;
6+ import java .nio .charset .Charset ;
7+
8+ /**
9+ * Created by shiqifeng on 2017/2/23.
10+ * Mail byhieg@gmail.com
11+ */
12+ public class BufferdOutputStreamExample {
13+
14+ public void writeToFile () throws Exception {
15+ String s = File .separator ;
16+ try (BufferedOutputStream bos = new BufferedOutputStream (new FileOutputStream ("D:" + s + "write_file.txt" ))) {
17+ for (int i = 0 ; i < 10000000 ; i ++) {
18+ String str = i + "" ;
19+ bos .write (str .getBytes (Charset .forName ("UTF-8" )));
20+ bos .flush ();
21+ }
22+ }
23+ }
24+ }
Original file line number Diff line number Diff line change 1+ package cn .byhieg .iotutorialtest ;
2+
3+ import cn .byhieg .iotutorial .bytestreamio .BufferdOutputStreamExample ;
4+ import junit .framework .TestCase ;
5+
6+ /**
7+ * Created by shiqifeng on 2017/2/23.
8+ * Mail byhieg@gmail.com
9+ */
10+ public class BufferdOutputStreamExampleTest extends TestCase {
11+ public void testWriteToFile () throws Exception {
12+ new BufferdOutputStreamExample ().writeToFile ();
13+
14+ }
15+
16+ }
You can’t perform that action at this time.
0 commit comments