Class WriteFileExtensions


  • public final class WriteFileExtensions
    extends java.lang.Object
    The class WriteFileExtensions provides methods for writing in files.
    • Method Summary

      All Methods Static Methods Concrete Methods 
      Modifier and Type Method Description
      static void readSourceFileAndWriteDestFile​(java.lang.String srcfile, java.lang.String destFile)
      Writes the source file with the best performance to the destination file.
      static void storeByteArrayToFile​(byte[] data, java.io.File file)
      Saves a byte array to the given file.
      static boolean string2File​(java.io.File file, java.lang.String string2write)
      The Method string2File(File, String) writes the String to the File.
      static boolean string2File​(java.io.File file, java.lang.String string2write, java.lang.String encoding)
      The Method string2File(File, String) writes the String to the File.
      static void string2File​(java.lang.String string2write, java.lang.String nameOfFile)
      The Method string2File() writes a String to the file.
      static void write​(java.io.InputStream inputStream, java.io.OutputStream outputStream)
      Writes the given input stream to the output stream.
      static void write2File​(java.io.Reader reader, java.io.Writer writer)
      The Method write2File() reads from an opened Reader and writes it to the opened Writer.
      static void write2File​(java.lang.String inputFile, java.io.Writer writer)
      The Method write2File() writes the File into the PrintWriter.
      static void write2File​(java.lang.String inputFile, java.lang.String outputFile)
      The Method write2File(String, String) copys a file from one filename to another.
      static void write2FileWithBuffer​(java.lang.String inputFile, java.lang.String outputFile)
      The Method write2FileWithBuffer() copy the content from one file to another.
      static void writeByteArrayToFile​(java.io.File file, byte[] byteArray)
      Writes the given byte array to the given file.
      static void writeByteArrayToFile​(java.lang.String filename, byte[] byteArray)
      Writes the given byte array to a file.
      static void writeLinesToFile​(java.io.File output, java.util.List<java.lang.String> input, java.lang.String encoding)
      Writes the input from the collection into the file.
      static void writeLinesToFile​(java.util.Collection<java.lang.String> collection, java.io.File output)
      Writes the input from the collection into the file.
      static void writeLinesToFile​(java.util.Collection<java.lang.String> collection, java.io.File output, java.lang.String encoding)
      Writes the input from the collection into the file.
      static void writeProperties2File​(java.lang.String filename, java.util.Properties properties)
      The Method writeProperties2File(String, Properties) writes the Properties to the file.
      static boolean writeStringToFile​(java.io.File file, java.lang.String string2write, java.lang.String encoding)
      The Method writeStringToFile(File, String, String) writes the String to the File.
      • Methods inherited from class java.lang.Object

        clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
    • Method Detail

      • readSourceFileAndWriteDestFile

        public static void readSourceFileAndWriteDestFile​(java.lang.String srcfile,
                                                          java.lang.String destFile)
                                                   throws java.io.IOException
        Writes the source file with the best performance to the destination file.
        Parameters:
        srcfile - The source file.
        destFile - The destination file.
        Throws:
        java.io.IOException - Signals that an I/O exception has occurred.
      • storeByteArrayToFile

        public static void storeByteArrayToFile​(byte[] data,
                                                java.io.File file)
                                         throws java.io.IOException
        Saves a byte array to the given file.
        Parameters:
        data - The byte array to be saved.
        file - The file to save the byte array.
        Throws:
        java.io.IOException - Signals that an I/O exception has occurred.
      • string2File

        public static boolean string2File​(java.io.File file,
                                          java.lang.String string2write)
                                   throws java.io.FileNotFoundException,
                                          java.io.IOException
        The Method string2File(File, String) writes the String to the File.
        Parameters:
        file - The File to write the String.
        string2write - The String to write into the File.
        Returns:
        The Method return true if the String was write successfull to the file otherwise false.
        Throws:
        java.io.FileNotFoundException - is thrown if an attempt to open the file denoted by a specified pathname has failed.
        java.io.IOException - Signals that an I/O exception has occurred.
      • string2File

        public static boolean string2File​(java.io.File file,
                                          java.lang.String string2write,
                                          java.lang.String encoding)
                                   throws java.io.FileNotFoundException,
                                          java.io.IOException
        The Method string2File(File, String) writes the String to the File.
        Parameters:
        file - The File to write the String.
        string2write - The String to write into the File.
        encoding - the encoding
        Returns:
        The Method return true if the String was write successfull to the file otherwise false.
        Throws:
        java.io.FileNotFoundException - is thrown if an attempt to open the file denoted by a specified pathname has failed.
        java.io.IOException - Signals that an I/O exception has occurred.
      • string2File

        public static void string2File​(java.lang.String string2write,
                                       java.lang.String nameOfFile)
                                throws java.io.IOException
        The Method string2File() writes a String to the file.
        Parameters:
        string2write - The String to write into the file.
        nameOfFile - The path to the file and name from the file from where we want to write the String.
        Throws:
        java.io.IOException - Signals that an I/O exception has occurred.
      • write

        public static void write​(java.io.InputStream inputStream,
                                 java.io.OutputStream outputStream)
                          throws java.io.FileNotFoundException,
                                 java.io.IOException
        Writes the given input stream to the output stream.
        Parameters:
        inputStream - the input stream
        outputStream - the output stream
        Throws:
        java.io.FileNotFoundException - the file not found exception
        java.io.IOException - Signals that an I/O exception has occurred.
      • write2File

        public static void write2File​(java.io.Reader reader,
                                      java.io.Writer writer)
                               throws java.io.IOException
        The Method write2File() reads from an opened Reader and writes it to the opened Writer.
        Parameters:
        reader - The opened Reader.
        writer - The opened Writer.
        Throws:
        java.io.IOException - Signals that an I/O exception has occurred.
      • write2File

        public static void write2File​(java.lang.String inputFile,
                                      java.lang.String outputFile)
                               throws java.io.FileNotFoundException,
                                      java.io.IOException
        The Method write2File(String, String) copys a file from one filename to another.
        Parameters:
        inputFile - The Name from the File to read and copy.
        outputFile - The Name from the File to write into.
        Throws:
        java.io.FileNotFoundException - is thrown if an attempt to open the file denoted by a specified pathname has failed.
        java.io.IOException - Signals that an I/O exception has occurred.
      • write2File

        public static void write2File​(java.lang.String inputFile,
                                      java.io.Writer writer)
                               throws java.io.FileNotFoundException,
                                      java.io.IOException
        The Method write2File() writes the File into the PrintWriter.
        Parameters:
        inputFile - The Name from the File to read and copy.
        writer - The PrintWriter to write into.
        Throws:
        java.io.FileNotFoundException - is thrown if an attempt to open the file denoted by a specified pathname has failed.
        java.io.IOException - Signals that an I/O exception has occurred.
      • write2FileWithBuffer

        public static void write2FileWithBuffer​(java.lang.String inputFile,
                                                java.lang.String outputFile)
                                         throws java.io.FileNotFoundException,
                                                java.io.IOException
        The Method write2FileWithBuffer() copy the content from one file to another. It use a buffer as the name says.
        Parameters:
        inputFile - The Path to the File and name from the file from where we read.
        outputFile - The Path to the File and name from the file from where we want to write.
        Throws:
        java.io.FileNotFoundException - is thrown if an attempt to open the file denoted by a specified pathname has failed.
        java.io.IOException - Signals that an I/O exception has occurred.
      • writeByteArrayToFile

        public static void writeByteArrayToFile​(java.io.File file,
                                                byte[] byteArray)
                                         throws java.io.IOException
        Writes the given byte array to the given file.
        Parameters:
        file - The file.
        byteArray - The byte array.
        Throws:
        java.io.IOException - Signals that an I/O exception has occurred.
      • writeByteArrayToFile

        public static void writeByteArrayToFile​(java.lang.String filename,
                                                byte[] byteArray)
                                         throws java.io.IOException
        Writes the given byte array to a file.
        Parameters:
        filename - The filename from the file.
        byteArray - The byte array.
        Throws:
        java.io.IOException - Signals that an I/O exception has occurred.
      • writeLinesToFile

        public static void writeLinesToFile​(java.util.Collection<java.lang.String> collection,
                                            java.io.File output)
                                     throws java.io.FileNotFoundException,
                                            java.io.IOException
        Writes the input from the collection into the file.
        Parameters:
        collection - The collection to write to file.
        output - The output-file.
        Throws:
        java.io.FileNotFoundException - is thrown if an attempt to open the file denoted by a specified pathname has failed.
        java.io.IOException - Signals that an I/O exception has occurred.
      • writeLinesToFile

        public static void writeLinesToFile​(java.util.Collection<java.lang.String> collection,
                                            java.io.File output,
                                            java.lang.String encoding)
                                     throws java.io.FileNotFoundException,
                                            java.io.IOException
        Writes the input from the collection into the file.
        Parameters:
        collection - The collection to write to file.
        output - The output-file.
        encoding - the encoding
        Throws:
        java.io.FileNotFoundException - is thrown if an attempt to open the file denoted by a specified pathname has failed.
        java.io.IOException - Signals that an I/O exception has occurred.
      • writeLinesToFile

        public static void writeLinesToFile​(java.io.File output,
                                            java.util.List<java.lang.String> input,
                                            java.lang.String encoding)
                                     throws java.io.FileNotFoundException,
                                            java.io.IOException
        Writes the input from the collection into the file.
        Parameters:
        output - The file to write the lines.
        input - The list with the input data.
        encoding - The encoding.
        Throws:
        java.io.FileNotFoundException - is thrown if an attempt to open the file denoted by a specified pathname has failed.
        java.io.IOException - Signals that an I/O exception has occurred.
      • writeProperties2File

        public static void writeProperties2File​(java.lang.String filename,
                                                java.util.Properties properties)
                                         throws java.io.IOException
        The Method writeProperties2File(String, Properties) writes the Properties to the file.
        Parameters:
        filename - The filename from the file to write the properties.
        properties - The properties.
        Throws:
        java.io.IOException - Signals that an I/O exception has occurred.
      • writeStringToFile

        public static boolean writeStringToFile​(java.io.File file,
                                                java.lang.String string2write,
                                                java.lang.String encoding)
                                         throws java.io.FileNotFoundException,
                                                java.io.IOException
        The Method writeStringToFile(File, String, String) writes the String to the File.
        Parameters:
        file - The File to write the String.
        string2write - The String to write into the File.
        encoding - The encoding from the file.
        Returns:
        The Method return true if the String was write successfull to the file otherwise false.
        Throws:
        java.io.FileNotFoundException - is thrown if an attempt to open the file denoted by a specified pathname has failed.
        java.io.IOException - Signals that an I/O exception has occurred.