File类

构造函数:  FIle file = new File(path);

常用函数:

是否存在:  file.exists()

文件名: file.getName()

父目录: file.getParent()

=================================================================

FileInputStream 类

构造方法: InputStream is = new InputStream(File file)

常用方法:

len =  is.read(buffer,off,len);   ---> len = is.read(buffer);

b     the buffer into which the data is read.

@return     the total number of bytes read into the buffer, or -1

FileOutputStream 类

构造方法: OutputStream os = new FileOutputStream(File file)

常用方法:

os.write(buffer,0,len)

BufferedInputStream 添加了缓冲区的输入流

构造方法: BufferedInputStream bis = new BufferedInputStream(FileInputStream fis);

常用方法:

bis.read(buffer,0,len);

BufferedOutputStream bos 添加了缓冲区的输出流

构造方法: BufferedOutputStream bos = new BufferedOutputStream(FileOutputStream fos);

常见方法:

bos.write(buffer,0, len);

bos.flush()

bos.close();

前提 序列化与反序列化 要继承接口 java.io.Serializable;

ObjectInputStream  对象的输入流, 实现对象的反序列化。

构造方法:  ObjectInputStream bis = new ObjectInputStream(FileInputStream fis);

主要方法:

bis.readObect();

ObjectOutputStream 对象的输出流, 实现对象的序列化

构造方法:  ObjectOutputStream bos = new ObjectOutputStream(FileOutputStream fos);

主要方法:

bos.write(object obj);

============================================================================================================

字节流:

InputStreamReader  字符输入流,输入内存中时, 已经将字节装换成 unicode 16位的字符编码。  解决了乱码的问题

构造方法:InputStreamReader isr = new InputStreamReader( FileInputStream fis );

常用方法

len = isr.read(char [] buffer, int off, int len)

OutputStreamWriter 字符输出流。   char

构造方法:  OutputStreamWriter osw = new OutputStreamWriter(FileOutputStream fos);

osw.write(char[] cbuff,off,len);

osw.flush()

osw.close()

FileReader 类

构造方法:  FileReader fr = new FileReader( new File(path) )

常用方法:

fr.read(char[] buff, int off, int len);

FileWriter 类

构造方法: FileWriter fw = new FileWriter(new File(Path))

常用方法:

fr.write(char[] buff, int off, int len);

BufferedReader  类    filereader.readLine()  return String  每次读取一行。

Reader r = new FileReader(new File("d:/w.txt"));
BufferedReader bReader = new BufferedReader(r); //String str = bReader.readLine();
String str = null; while( ( str = bReader.readLine() ) != null ){
System.out.println(str);
}

bufferedWriter 类

Writer w = new FileWriter(new File("d:/w.txt"));
BufferedWriter bw = new BufferedWriter(w);
String s = "叙利亚\r\n利比亚\r\n中国\r\n";
bw.write(s, , s.length());
bw.close();

IO 流小记录的更多相关文章

  1. 在网络编程中的io流小问题

    在客户端和服务端调用io流进行传输数据的过程中,当将数据write到outputstream中,需要及时刷新,否则会发生io阻塞. 在输入数据的时候,最好选用BufferedReader,因为read ...

  2. IO流小笔记

    File file=new File ();括号里面写路径 exists()判断文件是否存在:isfile()是判断已经存在的文件是文件还是目录: mkdir()和createNewFile()区别在 ...

  3. IO流简要总结

    IO流小总结 IO流的本质就是用于数据的传输,根据流的方向的不同,有输入流.输出流.根据数据类型的不同,又有字节流.字符流. 字节流 字节输入流   InputStream 字节输出流   Outpu ...

  4. Java基础IO流(二)字节流小案例

    JAVA基础IO流(一)https://www.cnblogs.com/deepSleeping/p/9693601.html ①读取指定文件内容,按照16进制输出到控制台 其中,Integer.to ...

  5. 二十一、Java基础--------IO流之综合案例分析

    前三篇文章详细介绍了IO流体系所涉及的重点内容,为了帮助理解与学习,本片博客主要是分析一个与IO操作相关的题目. 例1:在我们观看视频时经常要关注的就是视频的时间长度,在学习了IO操作之后,就可以自己 ...

  6. 【JAVA IO流之字符流】

    一.概述. java对数据的操作是通过流的方式.java用于操作流的对象都在IO包中.流按照操作数据不同分为两种,字节流和字符流.流按照流向分为输入流,输出流. 输入输出的“入”和“出”是相当于内存来 ...

  7. JavaEE基础(二十)/IO流

    1.IO流(IO流概述及其分类) 1.概念 IO流用来处理设备之间的数据传输 Java对数据的操作是通过流的方式 Java用于操作流的类都在IO包中 流按流向分为两种:输入流,输出流. 流按操作类型分 ...

  8. day20<IO流>

    IO流(IO流概述及其分类) IO流(FileInputStream) IO流(read()方法返回值为什么是int) IO流(FileOutputStream) IO流(FileOutputStre ...

  9. IO流大总结

    - - - - - - - - - - - - - - - 写在前面 - - - - - - - - - - - - - - - 1.概念 IO流用来处理设备之间的数据传输 Java对数据的操作是通过 ...

随机推荐

  1. android 获得View的高度

      在一个activity中有一个textview,设置字数不同,如何能在打开这个activity时就及时获得这个textview在activity的高度,有利于我对textview的高度进行设置. ...

  2. CFX构建webservice实例,与Spring整合.

    项目结构图: 步骤一: 添加maven包依赖 <project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi=&qu ...

  3. WRI$_ADV_OBJECTS表过大,导致PDB的SYSAUX表空间不足

    现象监控发现sysaux表空间使用不断增加,导致表空间不足 查看过程 查看版本: SQL> select * from v$version; BANNER CON_ID ------------ ...

  4. SharePoint Farm 3-Tier拓扑结构的实施解决方案

    难得的假期,难得有时间来梳理知识. 我写过很多关于SharePoint的安装和配置,有利用PowerShell的,也有图形安装界面的. 也演示了怎样创建一个双层的SharePoint Farm,怎样利 ...

  5. Android Error:Execution failed for task ':app:compileDebugJavaWithJavac' 解决方案

    今天使用 Android Studio 构建项目的时候出现了这个错误 compileDebugJavaWithJavac 通过搜索发现造成该问题的原因有很多需要结合具体的项目进行排查 通过 Andro ...

  6. Lua Linux环境下安装

    首先下载Lua包 解压缩 进入执行make linux 如果碰到lua.c:67:31: fatal error: readline/readline.h: No such file or direc ...

  7. Linux内核修炼之framebuffer分析

    Linux源代码包中/document/fb/framebuffer.txt有例如以下介绍: The frame buffer device provides an abstraction for t ...

  8. Multiplication of numbers

    Questin: There is an array A[N] of N numbers. You have to compose an array Output[N] such that Outpu ...

  9. Cocos2d-x 3.0 纹理

    1.纹理控制. Sprite *pSprite = Sprite::create("background.png"); TexParams params = {GL_NEAREST ...

  10. ajax实战用法详解

    谦虚使人进步,总结使人提高! 以下5个方法执行一般Ajax请求的简短形式,在处理复杂的Ajax请求时应该使用jQuery.ajax() 1.load(url,[data],[callback])载入远 ...