Package Summary  Overview Summary

method:readAllBytes(java.nio.file.Path) [CHANGED]

  • readAllBytes

    public static byte[] readAllBytes​(Path path)
                               throws IOException
    
    Reads all the bytes from a file. The method ensures that the file is closed when all bytes have been read or an I/O error, or other runtime exception, is thrown.

    Note that this method is intended for simple cases where it is convenient to read all bytes into a byte array. It is not intended for reading in large files.

    Parameters:
    path - the path to the file
    Returns:
    a byte array containing the bytes read from the file
    Throws:
    IOException - if an I/O error occurs reading from the stream
    java.lang.OutOfMemoryError - if an array of the required size cannot be allocated, for example the file is larger thatthan 2GB
    java.lang.SecurityException - In the case of the default provider, and a security manager is installed, the checkRead method is invoked to check read access to the file.
  • readAllBytes

    public static byte[] readAllBytes​(Path path)
                               throws IOException
    
    Reads all the bytes from a file. The method ensures that the file is closed when all bytes have been read or an I/O error, or other runtime exception, is thrown.

    Note that this method is intended for simple cases where it is convenient to read all bytes into a byte array. It is not intended for reading in large files.

    Parameters:
    path - the path to the file
    Returns:
    a byte array containing the bytes read from the file
    Throws:
    IOException - if an I/O error occurs reading from the stream
    java.lang.OutOfMemoryError - if an array of the required size cannot be allocated, for example the file is larger that 2GB
    java.lang.SecurityException - In the case of the default provider, and a security manager is installed, the checkRead method is invoked to check read access to the file.
  • readAllBytes

    public static byte[] readAllBytes​(Path path)
                               throws IOException
    
    Reads all the bytes from a file. The method ensures that the file is closed when all bytes have been read or an I/O error, or other runtime exception, is thrown.

    Note that this method is intended for simple cases where it is convenient to read all bytes into a byte array. It is not intended for reading in large files.

    Parameters:
    path - the path to the file
    Returns:
    a byte array containing the bytes read from the file
    Throws:
    IOException - if an I/O error occurs reading from the stream
    java.lang.OutOfMemoryError - if an array of the required size cannot be allocated, for example the file is larger than 2GB
    java.lang.SecurityException - In the case of the default provider, and a security manager is installed, the checkRead method is invoked to check read access to the file.

method:readString(java.nio.file.Path) [ADDED]

  • readString

    public static java.lang.String readString​(Path path)
                                       throws IOException
    
    Reads all content from a file into a string, decoding from bytes to characters using the UTF-8charset. The method ensures that the file is closed when all content have been read or an I/O error, or other runtime exception, is thrown.

    This method is equivalent to: readString(path, StandardCharsets.UTF_8)

    Parameters:
    path - the path to the file
    Returns:
    a String containing the content read from the file
    Throws:
    IOException - if an I/O error occurs reading from the file or a malformed or unmappable byte sequence is read
    java.lang.OutOfMemoryError - if the file is extremely large, for example larger than 2GB
    java.lang.SecurityException - In the case of the default provider, and a security manager is installed, the checkRead method is invoked to check read access to the file.
    Since:
    11

method:readString(java.nio.file.Path, java.nio.charset.Charset) [ADDED]

  • readString

    public static java.lang.String readString​(Path path,
                                              Charset cs)
                                       throws IOException
    
    Reads all characters from a file into a string, decoding from bytes to characters using the specified charset. The method ensures that the file is closed when all content have been read or an I/O error, or other runtime exception, is thrown.

    This method reads all content including the line separators in the middle and/or at the end. The resulting string will contain line separators as they appear in the file.

    API Note:
    This method is intended for simple cases where it is appropriate and convenient to read the content of a file into a String. It is not intended for reading very large files.
    Parameters:
    path - the path to the file
    cs - the charset to use for decoding
    Returns:
    a String containing the content read from the file
    Throws:
    IOException - if an I/O error occurs reading from the file or a malformed or unmappable byte sequence is read
    java.lang.OutOfMemoryError - if the file is extremely large, for example larger than 2GB
    java.lang.SecurityException - In the case of the default provider, and a security manager is installed, the checkRead method is invoked to check read access to the file.
    Since:
    11

method:writeString(java.nio.file.Path, java.lang.CharSequence, java.nio.file.OpenOption...) [ADDED]

  • writeString

    public static Path writeString​(Path path,
                                   java.lang.CharSequence csq,
                                   OpenOption... options)
                            throws IOException
    
    Write a CharSequence to a file. Characters are encoded into bytes using the UTF-8charset.

    This method is equivalent to: writeString(path, test, StandardCharsets.UTF_8, options)

    Parameters:
    path - the path to the file
    csq - the CharSequence to be written
    options - options specifying how the file is opened
    Returns:
    the path
    Throws:
    java.lang.IllegalArgumentException - if options contains an invalid combination of options
    IOException - if an I/O error occurs writing to or creating the file, or the text cannot be encoded using the specified charset
    java.lang.UnsupportedOperationException - if an unsupported option is specified
    java.lang.SecurityException - In the case of the default provider, and a security manager is installed, the checkWrite method is invoked to check write access to the file. The checkDelete method is invoked to check delete access if the file is opened with the DELETE_ON_CLOSE option.
    Since:
    11

method:writeString(java.nio.file.Path, java.lang.CharSequence, java.nio.charset.Charset, java.nio.file.OpenOption...) [ADDED]

  • writeString

    public static Path writeString​(Path path,
                                   java.lang.CharSequence csq,
                                   Charset cs,
                                   OpenOption... options)
                            throws IOException
    
    Write a CharSequence to a file. Characters are encoded into bytes using the specified charset.

    All characters are written as they are, including the line separators in the char sequence. No extra characters are added.

    The options parameter specifies how the file is created or opened. If no options are present then this method works as if the CREATE, TRUNCATE_EXISTING, and WRITE options are present. In other words, it opens the file for writing, creating the file if it doesn't exist, or initially truncating an existing regular-file to a size of 0.

    Parameters:
    path - the path to the file
    csq - the CharSequence to be written
    cs - the charset to use for encoding
    options - options specifying how the file is opened
    Returns:
    the path
    Throws:
    java.lang.IllegalArgumentException - if options contains an invalid combination of options
    IOException - if an I/O error occurs writing to or creating the file, or the text cannot be encoded using the specified charset
    java.lang.UnsupportedOperationException - if an unsupported option is specified
    java.lang.SecurityException - In the case of the default provider, and a security manager is installed, the checkWrite method is invoked to check write access to the file. The checkDelete method is invoked to check delete access if the file is opened with the DELETE_ON_CLOSE option.
    Since:
    11