JavaIO系统
来源:互联网 发布:linux上如何卸载mysql 编辑:程序博客网 时间:2024/06/04 19:24
Java I/O系统
流模式
- 概念:
源和目标之间建立的通道。 流的分类
- 当源是程序的时候 → 输出流
输出流:字节输出流(OutputStream)、字符输出流(Writer)(一个字节等于两个字符)。 当目标为程序的时候 → 输入流
输入流:字节输入流(InputStream)、字符输入流(Reader)(一个字节等于两个字符)。
//选择流分类FileInputStream fileInputStream = null;FileOutputStream fileOutputStream = null;//创建流对象try { fileInputStream = new FileInputStream("E:/YM.jpg"); fileOutputStream = new FileOutputStream("D:/MY.jpg");//操作流 int b = fileInputStream.read();//每 while((b=fileInputStream.read())!= -1){ fileOutputStream.write(b);} byte [] buffer = new byte [1024]; int length = 0; while ((length=fileInputStream.read(buffer))!= -1) { fileOutputStream.write(buffer, 0, length); fileOutputStream.flush(); } } catch (FileNotFoundException e) { // TODO Auto-generated catch block e.printStackTrace(); } catch (IOException e) { // TODO Auto-generated catch block e.printStackTrace(); }finally { //关闭流 if (fileInputStream != null) { try { fileInputStream.close(); }catch (IOException e) { // TODO Auto-generated catch block e.printStackTrace(); } }if(fileOutputStream != null){ try { fileOutputStream.close(); } catch (IOException e) { // TODO Auto-generated catch block e.printStackTrace(); }}}
- 当源是程序的时候 → 输出流
对象序列化与反序列化
要实现serializable接口(标记接口)- 序列化(Object InputStream)
概念:将对象以二进制流的形式输出 - 反序列化(Object OutputStream)
概念:将输入的二进制流转化为一个对象
- 序列化(Object InputStream)
0 0
- JavaIO 系统
- JavaIO系统
- 迷你javaio系统
- 迷你javaio系统
- JavaIO系统解析
- javaio
- JavaIO
- JavaIO
- JavaIO
- javaIO
- javaIO
- JAVAIO
- javaio
- javaio
- javaIO
- javaIO
- javaIO
- JavaIO
- 冒泡排序
- hdu4710 Balls Rearrangement(数学公式+取模)
- 简单立体几何和DP的结合
- HDU 1052田忌赛马 贪心+动态数组
- ANDROID开发笔记(三)在ANDROID中安装OPENCV
- JavaIO系统
- WampServer 2.5设置外网访问/局域网手机访问(403 Forbidden错误解决方法)
- Android控件架构与自定义控件详解(四)——事件拦截机制分析
- [POJ2262]Goldbach's Conjecture
- asp.net 学习记录3
- 如何使用Apktool
- 如何在不影响原有aapt源码的情况下编译定制版aapt
- 337_house_robber_III
- 百度之星——Problem D