import java.io.*;
public class E3 {
public static void main(String[] args) {
File file = new File("C:\\Users\\Administrator\\Desktop", "e3.txt");
byte[] a = "好的阿".getBytes();
//向文件写入内容
try {
FileOutputStream out = new FileOutputStream(file, false);
out.write(a);
out.close();
} catch (FileNotFoundException e) {
e.printStackTrace();
} catch (IOException e) {
e.printStackTrace();
}
//读取文件内容
try {
FileInputStream in = new FileInputStream(file);
byte n[]=new byte[9];//声明一个长度为9的字节数组
int fr=in.read(n);//读取文件
String s=new String(n,0,n.length);//把字符数组转化为字符串
System.out.println(s);
System.out.println(fr);
in.close();
} catch (FileNotFoundException e) {
e.printStackTrace();
} catch (IOException e) {
e.printStackTrace();
}
}
}
输入流FileInputStrean获取文件中的内容