File tree Expand file tree Collapse file tree
main/java/cn/byhieg/iotutorial/charsetstreamio
test/java/cn/byhieg/iotutorialtest Expand file tree Collapse file tree Original file line number Diff line number Diff line change 1+ package cn .byhieg .iotutorial .charsetstreamio ;
2+
3+ import java .io .File ;
4+ import java .io .FileReader ;
5+
6+ /**
7+ * Created by shiqifeng on 2017/2/23.
8+ * Mail byhieg@gmail.com
9+ */
10+ public class FileReaderExample {
11+
12+ public void readFromFile () throws Exception {
13+ try (FileReader reader = new FileReader ("D:" + File .separator + "read_file.txt" )) {
14+ char [] chars = new char [1024 ];
15+ while (reader .read (chars ) != -1 ) {
16+ System .out .println (chars );
17+ }
18+ }
19+ }
20+ }
Original file line number Diff line number Diff line change 1+ package cn .byhieg .iotutorial .charsetstreamio ;
2+
3+ import java .io .File ;
4+ import java .io .FileWriter ;
5+
6+ /**
7+ * Created by shiqifeng on 2017/2/23.
8+ * Mail byhieg@gmail.com
9+ */
10+ public class FileWriterExample {
11+
12+ public void writeToFile () throws Exception {
13+ try (FileWriter writer = new FileWriter ("D:" + File .separator + "write_file.txt" )) {
14+ for (int i = 0 ; i < 1000000 ;i ++) {
15+ writer .write ("我是byhieg" );
16+ }
17+ }
18+ }
19+ }
Original file line number Diff line number Diff line change @@ -14,7 +14,7 @@ public class OutputStreamWriterExample {
1414 public void writeToFile () throws Exception {
1515 try (Writer writer = new OutputStreamWriter (new FileOutputStream ("D:" + File .separator + "write_file.txt" ))) {
1616 for (int i = 0 ; i < 10000 ;i ++) {
17- writer .write (i + "" );
17+ writer .write ("我是中国人" + "" );
1818 writer .write ("\r \n " );
1919 }
2020 }
Original file line number Diff line number Diff line change 1+ package cn .byhieg .iotutorialtest ;
2+
3+ import cn .byhieg .iotutorial .charsetstreamio .FileReaderExample ;
4+ import junit .framework .TestCase ;
5+
6+ /**
7+ * Created by shiqifeng on 2017/2/23.
8+ * Mail byhieg@gmail.com
9+ */
10+ public class FileReaderExampleTest extends TestCase {
11+ public void testReadFromFile () throws Exception {
12+ new FileReaderExample ().readFromFile ();
13+ }
14+
15+ }
Original file line number Diff line number Diff line change 1+ package cn .byhieg .iotutorialtest ;
2+
3+ import cn .byhieg .iotutorial .charsetstreamio .FileWriterExample ;
4+ import junit .framework .TestCase ;
5+
6+ /**
7+ * Created by shiqifeng on 2017/2/23.
8+ * Mail byhieg@gmail.com
9+ */
10+ public class FileWriterExampleTest extends TestCase {
11+ public void testWriteToFile () throws Exception {
12+ new FileWriterExample ().writeToFile ();
13+ }
14+
15+ }
You can’t perform that action at this time.
0 commit comments