JavaI/O流
InputStream / OutputStream
I/O流基本编程模型
1、构建源和目的地连接
2、从源输出流
3、从目的地接收流
4、关闭连接
InputStream / OutputStream
I/O流基本编程模型
1、构建源和目的地连接
2、从源输出流
3、从目的地接收流
4、关闭连接
public static void readFile(){
try{
FileInputStream fis = new FileInputStream("fs.txt");
byte[] bys = new byte[1024] ;
int len=fis.read(bys);
System.out.println(new String(bys,0,len));
fis.close();
}catch(Exception e){
e.printStackTrace();
}
}
public static void writeFile(){
try{
FileOutputStream fos = new FileOutputStream("fs.txt");
String str = "hello world";
fos.write(str.getBytes());
fos.close();
}catch(Exception e){
e.printStackTrace();
}
}
}