【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 = "\n";
public static final String LINE_SEPARATOR_WINDOWS = "\r\n";
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

    返回字符串

 

转载于:https://www.cnblogs.com/jiangbei/p/8384486.html

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值