Commons-IO学习之IOUtils

public class IOUtils extends Object
General IO stream manipulation utilities. 

public static boolean contentEquals(InputStream input1,InputStream input2) throws IOException  用于比较两个文件内的内容是否一致

public static boolean contentEquals(Reader input1,Reader input2)  throws IOException  用于比较两个文件内的内容是否一致

public static int copy(InputStream input,OutputStream output)throws IOException

public static void copy(InputStream input,Writer output)throws IOException
IOUtils.copy(new FileInputStream(new File("e:/1.txt")),new FileOutputStream(new File("f:/1.txt")));

public static long copyLarge(InputStream input,OutputStream output)
throws IOException

public static long copyLarge(Reader input,Writer output) throws IOException

public static void copy(Reader input,OutputStream output) throws IOException

public static void copy(Reader input,OutputStream output,String encoding)throws IOException

public static LineIterator lineIterator(InputStream input,Charset encoding)throws IOException
FileInputStream stream=new FileInputStream(new File("f:/1.txt"));
try {
	LineIterator it = IOUtils.lineIterator(stream, "utf-8");
	while (it.hasNext()) {
		String line = it.nextLine();
		System.out.println(line);
	}
} finally {
	IOUtils.closeQuietly(stream);
}

public static LineIterator lineIterator(Reader reader)
Return an Iterator for the lines in a Reader.

public static List<String> readLines(InputStream input)throws IOException
Get the contents of an InputStream as a list of Strings, one entry per line, using the default character encoding of the platform.

public static InputStream toBufferedInputStream(InputStream input)
throws IOException
Fetches entire contents of an InputStream and represent same data as result InputStream. 

public static BufferedReader toBufferedReader(Reader reader)
Returns the given reader if it is a BufferedReader, otherwise creates a toBufferedReader for the given reader. 

public static byte[] toByteArray(InputStream input)throws IOException
Get the contents of an InputStream as a byte[]. 

public static byte[] toByteArray(InputStream input,int size)throws IOException

public static byte[] toByteArray(Reader input)throws IOException

public static byte[] toByteArray(Reader input,Charset encoding)
throws IOException

public static byte[] toByteArray(URI uri)throws IOException

public static byte[] toByteArray(URL url)throws IOException
Get the contents of a URL as a byte[]. 

public static char[] toCharArray(InputStream is)throws IOException

public static char[] toCharArray(InputStream is,String encoding)
throws IOException

public static char[] toCharArray(InputStream is,Charset encoding)
throws IOException
public static Charset forName(String charsetName)
返回指定 charset 的 charset 对象。

public static InputStream toInputStream(CharSequence input)
Convert the specified CharSequence to an input stream, encoded as bytes using the default character encoding of the platform. 
java.lang 
Interface CharSequence
All Known Subinterfaces: 
Name 
All Known Implementing Classes: 
CharBuffer, Segment, String, StringBuffer, StringBuilder 


public static InputStream toInputStream(CharSequence input,Charset encoding)
Convert the specified CharSequence to an input stream, encoded as bytes using the specified character encoding. 

public static InputStream toInputStream(CharSequence input,String encoding)throws IOException

public static InputStream toInputStream(String input)

public static String toString(Reader input)throws IOException

public static String toString(URI uri)throws IOException

public static String toString(URI uri,Charset encoding)throws IOException

public static String toString(URI uri,String encoding)throws IOException
Gets the contents at the given URI. 

public static String toString(URL url)throws IOException
Gets the contents at the given URL. 

public static void write(byte[] data,OutputStream output)throws IOException
Writes bytes from a byte[] to an OutputStream. 

public static void write(byte[] data,Writer output)throws IOException
	Writes bytes from a byte[] to chars on a Writer using the default character encoding of the platform. 

public static void write(byte[] data,Writer output,Charset encoding)
throws IOException

public static void write(char[] data,OutputStream output)throws IOException
Writes chars from a char[] to bytes on an OutputStream. 


 

参考commons-io api

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 打赏
    打赏
  • 0
    评论
commons-io是一个开源的Java类库,提供了许多实用的IO(输入/输出)工具类,用于简化Java程序中的文件和流操作。它是Apache Commons项目的一部分,旨在提供常见的IO操作的实现和工具。 commons-io提供了许多功能强大且易于使用的类和方法,包括文件操作、流操作、字节操作、字符操作等。其中一些常用的功能包括: 1. 文件操作:commons-io提供了一系列用于文件操作的工具类,如FileUtils类,可以方便地进文件的复制、移动、删除、重命名等操作。 2. 流操作:commons-io提供了一些用于流操作的工具类,如IOUtils类,可以方便地进流的读取、写入、复制等操作。它还提供了一些特殊类型的流,如NullInputStream、NullOutputStream等,用于模拟空输入输出。 3. 字节操作:commons-io提供了一些用于字节操作的工具类,如ByteUtils类,可以方便地进字节的转换、比较、填充等操作。 4. 字符操作:commons-io提供了一些用于字符操作的工具类,如CharUtils类,可以方便地进字符的转换、判断、查找等操作。 5. 文件过滤器:commons-io提供了一些用于文件过滤的工具类,如FileFilterUtils类,可以方便地进文件过滤操作,例如按文件名、文件类型等进过滤。 6. 异常处理:commons-io提供了一些用于异常处理的工具类,如ExceptionUtils类,可以方便地进异常的捕获、包装、打印等操作。
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包

打赏作者

wiksys

你的鼓励将是我创作的最大动力

¥1 ¥2 ¥4 ¥6 ¥10 ¥20
扫码支付:¥1
获取中
扫码支付

您的余额不足,请更换扫码支付或充值

打赏作者

实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

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

余额充值