zoukankan      html  css  js  c++  java
  • 【commons】IO工具类——commons-io之IOUtils

    本文转载自xingoo:

      https://www.cnblogs.com/xing901022/p/5978989.html

    一、常用静态变量

    public static final char DIR_SEPARATOR_UNIX = '/';
    public static final char DIR_SEPARATOR_WINDOWS = '\';
    public static final char DIR_SEPARATOR;
    public static final String LINE_SEPARATOR_UNIX = "
    ";
    public static final String LINE_SEPARATOR_WINDOWS = "
    ";
    public static final String LINE_SEPARATOR;
    
    
    static {
        DIR_SEPARATOR = File.separatorChar;
        
        StringBuilderWriter buf = new StringBuilderWriter(4);
        PrintWriter out = new PrintWriter(buf);
        out.println();
        LINE_SEPARATOR = buf.toString();
        out.close();
    }

    二、常用方法 

      copy

      这个方法可以拷贝流,算是这个工具类中使用最多的方法了。支持多种数据间的拷贝:

    copy(inputstream,outputstream)
    copy(inputstream,writer)
    copy(inputstream,writer,encoding)
    copy(reader,outputstream)
    copy(reader,writer)
    copy(reader,writer,encoding)

      copy内部使用的其实还是copyLarge方法。因为copy能拷贝Integer.MAX_VALUE的字节数据,即2^31-1。、

      copyLarge类似,不过适合于拷贝2G的大数据

      以下主要方法不再赘述,参考上文链接

      完整API请参考官方API 

      read

        从一个流中读取内容

      readFully

        这个方法会读取指定长度的流,如果读取的长度不够,就会抛出异常

      readLines

        readLines方法可以从流中读取内容,并转换为String的list

      skip

        这个方法用于跳过指定长度的流,

      skipFully

        这个方法类似skip,只是如果忽略的长度大于现有的长度,就会抛出异常

      write

        这个方法可以把数据写入到输出流中

      writeLines

        这个方法可以把string的List写入到输出流中

      close

        关闭URL连接

      closeQuietly

        忽略nulls和异常,关闭某个流

      contentEquals

        比较两个流是否相同

      contentEqualsIgnoreEOL

        比较两个流,忽略换行符

      lineIterator

        读取流,返回迭代器

      toBufferedInputStream

        把流的全部内容放在另一个流中

      toBufferedReader

        返回输入流

      toByteArray

        返回字节数组

      toCharArray

        返回字符数组

      toInputStream

        返回输入流

      toString

        返回字符串

  • 相关阅读:
    直线的中点Bresenham算法的实现
    使用git 将自己的本地文件git到github上面的完整过程
    利用Microsoft VC++6.0 的MFC 的绘图工具实现简单图形的绘制
    github常见操作和常见错误及其解决办法
    浅谈软件配置管理工具(github & SVN)
    为Github 托管项目的访问添加SSH keys
    jQuery:用 lightTreeview 实现树形分类菜单的功能 展开收缩分类代码
    程序设计7大面向对象设计原则
    计算机组成原理实验之模拟整机实验考核试题
    计算机组成原理实验之CPU组成与指令周期实验
  • 原文地址:https://www.cnblogs.com/jiangbei/p/8384486.html
Copyright © 2011-2022 走看看