IO流的基本概念
1.基类
InputStream,OutputStream.都是接口.
2.流的分类
a.处理
字节流和字符流
字节流由InputStream和OutputStream处理,而字符流由Reader和Writer处理。
b.输入和输出
3.流的基本创建方法
InputStream inputStream = new FileInputStream(String filepath);
OutputStream outputSteam = new FileOutputStream(String filepath);
File 有3中创建对象的方法
File file = new File(String filepath);
File file = new File(File file,String fileName);
File file = new File(String filepath,String fileName);
4.最常用的方法
read--完成返回值-1,write,flash.
5.实例
InputStream inputs =null;OutputStream output =null;try {inputs = new FileInputStream(fromFile);output = new FileOutputStream(tofile);byte[] b = new byte[1024];int len = inputs.read(b);while(len!=-1){output.write(b, 0, len);len = inputs.read(b);}//System.out.println("----------copy successful-------------");} catch (FileNotFoundException e) {e.printStackTrace();} catch (IOException e) {e.printStackTrace();}finally{if(inputs!=null){try {inputs.close();} catch (IOException e) {e.printStackTrace();}}if(output!=null){try {output.close();} catch (IOException e) {e.printStackTrace();}}}