zoukankan      html  css  js  c++  java
  • Commons IO

    IOUtils is a general IO stream manipulation utilities. This class provides static utility methods for input/output operations.

    • closeQuietly - these methods close a stream ignoring nulls and exceptions
    • toXxx/read - these methods read data from a stream
    • write - these methods write data to a stream
    • copy - these methods copy all the data from one stream to another
    • contentEquals - these methods compare the content of two streams

    Constant Field Values

     Modifier and Type  Field Description
     static char  DIR_SEPARATOR  The system directory separator character.
     static char  DIR_SEPARATOR_UNIX  The Unix directory separator character.
     static char  DIR_SEPARATOR_WINDOWS  The Windows directory separator character. 
     static int  EOF  Represents the end-of-file (or stream).
     static String  LINE_SEPARATOR  The system line separator string.
     static String  LINE_SEPARATOR_UNIX  The Unix line separator string.
     static String  LINE_SEPARATOR_WINDOWS   The Windows line separator string.

    Common Methods

    closeQuietly: Close a stream ignoring nulls and exceptions.

    InputStream in = ...;
    try {
        // do something with the stream
    } finally {
        IOUtils.closeQuietly(in);
    }

    readLines: Gets the contents of an InputStream as a list of Strings, one entry per line.

    List<String> lines = IOUtils.readLines(in);

    toByteArray: Gets the contents of an InputStream(, String, URL) as a byte[].

    byte[] byteArray = IOUtils.toByteArray(new URL("http://www.example.com/"));

    toCharArray: Gets the contents of an InputStream(, Reader) as a character array.

    char[] byteArray = IOUtils.toCharArray(in);

    toInputStream: Converts the specified string(, CharSequence) to an input stream.

    InputStream in = IOUtils.toInputStream("string");

    toString: Gets the contents of an InputStream(, byte[], URL...) as a String

    String str = IOUtils.toString(in);

    更多请参考:http://commons.apache.org/proper/commons-io/javadocs/api-release/index.html?org/apache/commons/io/IOUtils.html

  • 相关阅读:
    [USACO11DEC]牧草种植Grass Planting
    [LNOI2014]LCA
    PTA的Python练习题(九)
    竞争条件攻击
    burpsuite使用--暴力破解
    PTA的Python练习题(八)
    PTA的Python练习题(七)
    PTA的Python练习题(六)
    攻防世界Web进阶-Upload1
    BugkuCTF解题Web基础(一)
  • 原文地址:https://www.cnblogs.com/huey/p/5484970.html
Copyright © 2011-2022 走看看