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