Skip to content

Commit 39249f0

Browse files
committed
增加ByteArrayOutputStream例子
1 parent 6ad35e5 commit 39249f0

5 files changed

Lines changed: 42 additions & 3 deletions

File tree

src/main/java/cn/byhieg/annotationstutorial/AMethodProcess.java

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,5 @@
11
package cn.byhieg.annotationstutorial;
22

3-
import sun.jvm.hotspot.runtime.amd64.AMD64CurrentFrameGuess;
43

54
import java.lang.reflect.InvocationTargetException;
65
import java.lang.reflect.Method;

src/main/java/cn/byhieg/collectiontutorial/listtutorial/SimpleLinkedList.java

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,5 @@
11
package cn.byhieg.collectiontutorial.listtutorial;
22

3-
import apple.laf.JRSUIFocus;
4-
53
/**
64
* Created by byhieg on 17/2/15.
75
* Mail to byhieg@gmail.com
Lines changed: 27 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,27 @@
1+
package cn.byhieg.iotutorial.bytestreamio;
2+
3+
import java.io.ByteArrayOutputStream;
4+
import java.io.FileInputStream;
5+
import java.io.FileNotFoundException;
6+
import java.io.InputStream;
7+
8+
/**
9+
* Created by shiqifeng on 2017/2/23.
10+
* Mail byhieg@gmail.com
11+
*/
12+
public class ByteArrayOutPutStreamExample {
13+
14+
public void writeFromFile() throws Exception {
15+
try (InputStream is = new FileInputStream("D://read_file.txt")) {
16+
ByteArrayOutputStream output = new ByteArrayOutputStream();
17+
byte[] bytes = new byte[1024];
18+
while (is.read(bytes) != -1) {
19+
output.write(bytes);
20+
}
21+
22+
String data = output.toString("UTF-8");
23+
System.out.println(data);
24+
25+
}
26+
}
27+
}

src/main/java/cn/byhieg/iotutorial/bytestreamio/write_file.txt

Whitespace-only changes.
Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,15 @@
1+
package cn.byhieg.iotutorialtest;
2+
3+
import cn.byhieg.iotutorial.bytestreamio.ByteArrayOutPutStreamExample;
4+
import junit.framework.TestCase;
5+
6+
/**
7+
* Created by shiqifeng on 2017/2/23.
8+
* Mail byhieg@gmail.com
9+
*/
10+
public class ByteArrayOutPutStreamExampleTest extends TestCase {
11+
public void testWriteFromFile() throws Exception {
12+
new ByteArrayOutPutStreamExample().writeFromFile();
13+
}
14+
15+
}

0 commit comments

Comments
 (0)