Note/安卓/第三章:数据输入输出流.md

28 lines
689 B
Markdown

输入流:从文件中 读 到程序中
输出流:从程序中 写 到文件中
数据源 目的地
```java
1. b.txt hello 输出
// bytes 数据源 fos.write() b.txt目的地
File file=new File("E:/b.txt");
FileOutputStream fos=new FileOutputStream(file);
String str="hello"; //数据源
byte[] bytes = str.getBytes();
fos.write(bytes);
fos.close();
// 2.b.txt 读 输入
FileInputStream fis=new FileInputStream(file);
byte[] bytes1=new byte[fis.available()];
fis.read(bytes1);
System.out.println(new String(bytes1));
fis.close();
```