Skip to content

Commit f276ee2

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

5 files changed

Lines changed: 76 additions & 1 deletion

File tree

Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,22 @@
1+
package cn.byhieg.iotutorial.charsetstreamio;
2+
3+
import java.io.File;
4+
import java.io.FileInputStream;
5+
import java.io.InputStreamReader;
6+
import java.io.Reader;
7+
8+
/**
9+
* Created by shiqifeng on 2017/2/23.
10+
* Mail byhieg@gmail.com
11+
*/
12+
public class InputStreamReaderExample {
13+
14+
public void readFromFile() throws Exception{
15+
try (Reader reader = new InputStreamReader(new FileInputStream("D:" + File.separator + "read_file.txt"))) {
16+
char[] chars = new char[1024];
17+
while (reader.read(chars) != -1){
18+
System.out.print(new String(chars));
19+
}
20+
}
21+
}
22+
}
Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,22 @@
1+
package cn.byhieg.iotutorial.charsetstreamio;
2+
3+
import java.io.File;
4+
import java.io.FileOutputStream;
5+
import java.io.OutputStreamWriter;
6+
import java.io.Writer;
7+
8+
/**
9+
* Created by shiqifeng on 2017/2/23.
10+
* Mail byhieg@gmail.com
11+
*/
12+
public class OutputStreamWriterExample {
13+
14+
public void writeToFile() throws Exception{
15+
try (Writer writer = new OutputStreamWriter(new FileOutputStream("D:" + File.separator + "write_file.txt"))) {
16+
for (int i = 0 ; i < 10000;i++) {
17+
writer.write(i + "");
18+
writer.write("\r\n");
19+
}
20+
}
21+
}
22+
}

src/test/java/cn/byhieg/iotutorialtest/BufferdOutputStreamExampleTest.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -13,4 +13,4 @@ public void testWriteToFile() throws Exception {
1313

1414
}
1515

16-
}
16+
}
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.charsetstreamio.InputStreamReaderExample;
4+
import junit.framework.TestCase;
5+
6+
/**
7+
* Created by shiqifeng on 2017/2/23.
8+
* Mail byhieg@gmail.com
9+
*/
10+
public class InputStreamReaderExampleTest extends TestCase {
11+
public void testReadFromFile() throws Exception {
12+
new InputStreamReaderExample().readFromFile();
13+
}
14+
15+
}
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.charsetstreamio.OutputStreamWriterExample;
4+
import junit.framework.TestCase;
5+
6+
/**
7+
* Created by shiqifeng on 2017/2/23.
8+
* Mail byhieg@gmail.com
9+
*/
10+
public class OutputStreamWriterExampleTest extends TestCase {
11+
12+
public void testWriteToFile() throws Exception {
13+
new OutputStreamWriterExample().writeToFile();
14+
}
15+
16+
}

0 commit comments

Comments
 (0)