public static File createFile ( String filePath ) throws IOException { boolean isDirectory = filePath . endsWith ( "/" ) || filePath . endsWith ( "\\" ) ; String formattedFilePath = formatFilePath ( filePath ) ; File f = new File ( formattedFilePath ) ; if ( f . exists ( ) ) { return f ; } if ( isDirectory ) { f . mkdirs ( ) ; } else { f . getParentFile ( ) . mkdirs ( ) ; f . createNewFile ( ) ; } if ( f . exists ( ) ) { f . setExecutable ( true , false ) ; f . setReadable ( true , false ) ; f . setWritable ( true , false ) ; return f ; } throw new IOException ( "Error creating file: " + f . getAbsolutePath ( ) ) ; }
Creates a file in the specified path . Creates also any necessary folder needed to achieve the file level of nesting .