![](https://csdnimg.cn/release/download_crawler_static/88481980/bg4.jpg)
19. System.out.println(new String(b));
20. } catch (Exception e) {
21. e.printStackTrace();
22. } finally {
23. try {
24. if (in != null) {
25. in.close();
26. in = null;
27. }
28. } catch (Exception e) {
29. }
30. }
31. }
32.
33. public static void main(String[] args) {
34. InputStreamDemo id = new InputStreamDemo();
35. String src = "D:" + File.separator + "hello.txt";
36. id.readFile(src);
37. }
38.
39. }
OutputStreamDemo
讲完了 InputStream 来讲 OutputStream,输出内容至外部的一个文件
[java] view plaincopy
1. package org.sky.io;
2.
3. import java.io.*;
4.
5. public class OutputStreamDemo {
6.
7. public void writeWithByte() {
8. String fileName = "D:" + File.separator + "hello.txt";
9. OutputStream out = null;
10. File f = new File(fileName);
11. try {
12. out = new FileOutputStream(f, true);
13. String str = " [Publicity ministry of ShangHai Municipal commi
ttee of CPC]";
14. byte[] b = str.getBytes();
15. out.write(b);