概述
- 作用
- 文件操作类
- 流示例
作用
- 读写文件
文件操作
- File 类
- 文件的各种操作都是这个类,如,对文件的增删改查
流示例
- 控制台输入流
public static void main(String[] args) { InputStream is=System.in; try { byte[]bs=new byte[10]; while(is.read(bs)!=-1){ String str=new String(bs).trim(); System.out.println(str); } is.close(); } catch (IOException e) { e.printStackTrace(); } }
- 控制台输出流
public static void main(String[] args) { OutputStream out=System.out; try { byte[]bs="system.out.use\n".getBytes(); out.write(bs); bs="another".getBytes(); out.write(bs); out.close(); } catch (IOException e) { e.printStackTrace(); } }
控制台输出流控制台输出流控制台输出流控制台输出流控制台输出流