commons-dev mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From "deng xinzi" <xinzi6...@gmail.com>
Subject [bug]commons-io 1.3 FileUtils.openOutputStream(File file) NullPointException
Date Sun, 04 Feb 2007 14:18:58 GMT
FileUtils.openOutputStream(File file)
When the file = new File( "abc.txt" );
There will be a NullPointerException throw.
Cause
file = new File("abc.txt")
file.getParentFile() returns null.

So I suggest adding the null check code like this.

            File parent = file.getParentFile();
            if( parent != null ) {   // ADD THIS!!!
              if (parent.exists() == false) {
                if (parent.mkdirs() == false) {
                    throw new IOException("File '" + file + "' could not be
created");
                }
              }
            }


                                       Xinzi ...

Mime
  • Unnamed multipart/alternative (inline, None, 0 bytes)
View raw message