Uploaded image for project: 'Commons IO'
  1. Commons IO
  2. IO-620

FileUtils.writeStringToFile does not close() stream

    XMLWordPrintableJSON

Details

    • Bug
    • Status: Resolved
    • Major
    • Resolution: Not A Problem
    • 2.6
    • None
    • Streams/Writers
    • None

    Description

      FileUtils.writeStringToFile() method does not close the OutputStream.  This can lead to running out of file descriptors, inability to write to the file a second time (Windows), and unpredictable file contents (Unix).

          public static void writeStringToFile(final File file, final String data, final Charset encoding,
                                               final boolean append) throws IOException {
              try (OutputStream out = openOutputStream(file, append))

      {             IOUtils.write(data, out, encoding);         }

          }

       

      The stream is closed in version 2.5, but not in 2.6.  It may have been introduced on the following commit:

      https://github.com/apache/commons-io/commit/4dc97b64005f0083b2facaa70f661138a4fa3fc0#diff-5999114d4c52063bbe7063696cf20215

      Attachments

        Activity

          People

            Unassigned Unassigned
            erilong Eric Long
            Votes:
            0 Vote for this issue
            Watchers:
            1 Start watching this issue

            Dates

              Created:
              Updated:
              Resolved: