码迷,mamicode.com
首页 > 其他好文 > 详细

【commons】IO工具类——commons-io之IOUtils

时间:2018-01-30 16:59:49      阅读:181      评论:0      收藏:0      [点我收藏+]

标签:targe   ignore   数组   tput   适合   str   seq   字节   file   

本文转载自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

    返回字符串

 

【commons】IO工具类——commons-io之IOUtils

标签:targe   ignore   数组   tput   适合   str   seq   字节   file   

原文地址:https://www.cnblogs.com/jiangbei/p/8384486.html

(0)
(0)
   
举报
评论 一句话评论(0
登录后才能评论!
© 2014 mamicode.com 版权所有  联系我们:gaon5@hotmail.com
迷上了代码!