Skip to content

Commit 99d0dbf

Browse files
committed
添加代码
1 parent 34dede5 commit 99d0dbf

File tree

2 files changed

+40
-0
lines changed

2 files changed

+40
-0
lines changed
Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,24 @@
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+
}
Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,16 @@
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+
}

0 commit comments

Comments
 (0)