十、输入/输出

  流:一组有序的数据序列。

1、输入流

  所有输入流都是抽象类InputStream或抽象类Reader的子类。

  方法:read()、mark()、reset()、skip()、markSupport()、close()

2、输出流

  所有输出流都是抽象类OuputStream或抽象类Writer的子类

  方法:write()、flush()、close()

3、File类

  io包中唯一代表磁盘文件本身的对象。

(1)文件的创建与删除

  1)File file = new File("d:/1.txt");

  2)new File(String parent,String child)

  3)new File(File f,String child)

  createNewFile()、delete()

(2)获取文件信息

  方法:getName()、canRead()、canWrite()、exits()、length()、getAbsolutePath()、getParent()、isFile()、isDirectory()、isHidden()、lastModified()

4、文件输入/输出流

  对应字节或字节数组

(1)FileInputStream与FIleOutputStream类

  FileInputStream构造方法:

  1)FileInputStream(String name)

  2)FileOutputStream(File file)

(2)FIleReader类和FileWriter类

  对应字符

  read()、write()

5、带缓存的输入/输入流

(1)BufferedInputStream类与BufferedOutputStream类

  BufferedInputStream构造方法:

    1)BufferedInputStream(InputStream in)  //默认32个字节

    2)BufferedInputStream(InputStream in,int size)

(2)BufferedReader类与BufferedWriter类

  方法:read()、readLine()、write()、flush()、nextLine()

6、数据输入/输出流

  DataInputStream类与DataOutputStream类

  方法:writreBytes(String s)、writeChar(String s)、writeUTF(String s)

     readUTF()

7、ZIP压缩输入/输出流

(1)压缩文件  ZipOutputStream

  方法:putNextEntry(ZipEntry e)、write(byte[] b,int off,int len)、finish()、

setComment(String comment)

(2)解压缩  ZipInputStream

  方法:read()、available()、closeEntry()、skip()、getNextEntry()、createZipEntry()

  

 

posted @ 2016-10-27 11:00  yl007  阅读(170)  评论(0编辑  收藏  举报