Class IOUtils


  • public class IOUtils
    extends Object
    Input / output utilities.
    Version:
    2020-02-23
    Author:
    Vladimir Dzhuvinov
    • Method Detail

      • readInputStreamToString

        public static String readInputStreamToString​(InputStream stream)
                                              throws IOException
        Reads the specified input stream into a string using UTF-8 character set encoding.
        Parameters:
        stream - The input stream. Must not be null.
        Returns:
        The string.
        Throws:
        IOException - If an input exception is encountered.
      • readInputStreamToString

        public static String readInputStreamToString​(InputStream stream,
                                                     Charset charset)
                                              throws IOException
        Reads the specified input stream into a string.
        Parameters:
        stream - The input stream. Must not be null.
        charset - The expected character set. Must not be null.
        Returns:
        The string.
        Throws:
        IOException - If an input exception is encountered.
      • readFileToString

        public static String readFileToString​(File file)
                                       throws IOException
        Reads the content of the specified file into a string using UTF-8 character set encoding.
        Parameters:
        file - The file. Must not be null.
        Returns:
        The string.
        Throws:
        IOException - If an input exception is encountered.
      • readFileToString

        public static String readFileToString​(File file,
                                              Charset charset)
                                       throws IOException
        Reads the content of the specified file into a string.
        Parameters:
        file - The file. Must not be null.
        charset - The expected character set. Must not be null.
        Returns:
        The string.
        Throws:
        IOException - If an input exception is encountered.