**
FileInputStream 和 FileOutputStream进行写文件和读文件**
基础知识FileInputStream和FileOutputStream都是字节输入输出流抽象类。
#代码块
import java.io.*;
import java.util.Scanner;
public class test {
public static void main(String[] args) throws IOException {
//创建文件
File file = new File("G:\file.txt");
if(!file.exists()){
file.createNewFile();
System.out.println(file.getName()+"文件已创建!");
}
//写入文件
try{
FileOutputStream fo = new FileOutputStream(file);
byte []buy = "今天你emo了吗?".getBytes();
fo.write(buy);
fo.close();
//读取文件
FileInputStream fi = new FileInputStream(file);
byte []byt = new byte[2014];
int len = fi.read(byt);//fi.read(byt)返回字节数组byt的字节数
System.out.println("文件的信息是:"+new String(byt,0,len));
fi.close();
}catch(Exception E){
E.printStackTrace();
}
}
}
运行结果



