private FileOutputStream createFileOutputStream ( String newFileName , boolean append ) throws FileNotFoundException { try { // // attempt to create file // return new FileOutputStream ( newFileName , append ) ; } catch ( FileNotFoundException ex ) { // // if parent directory does not exist then // attempt to create it and try to create file // see bug 9150 // String parentName = new File ( newFileName ) . getParent ( ) ; if ( parentName != null ) { File parentDir = new File ( parentName ) ; if ( ! parentDir . exists ( ) && parentDir . mkdirs ( ) ) { return new FileOutputStream ( newFileName , append ) ; } else { throw ex ; } } else { throw ex ; } } }
Creates a new FileOutputStream of a new log file possibly creating first all the needed parent directories