Hello Xinzi:

I've created this JIRA ticket to track your issue:

[IO-112] NPE in FileUtils.openOutputStream(File) when file has no parent in 
path.
http://issues.apache.org/jira/browse/IO-112

I've also committed a fix in SVN. You can rebuild from the SVN sources yourself 
or wait for the next nightly build.

Thank you,
Gary

> -----Original Message-----
> From: deng xinzi [mailto:[EMAIL PROTECTED]
> Sent: Sunday, February 04, 2007 6:19 AM
> To: [email protected]
> Subject: [bug]commons-io 1.3 FileUtils.openOutputStream(File file)
> NullPointException
>
> 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 ...

---------------------------------------------------------------------
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]

Reply via email to