FileUtil { public static boolean createNewFile( final String fileAbsPath ) { if ( StringUtils.isBlank( fileAbsPath ) ) { logger.error( "In createNewFile, file absolute path '{}' is either null or blank.", fileAbsPath ); return false; } File file = new File( fileAbsPath ); String parent = file.getParent(); File parentFile = new File( parent ); if ( parentFile.exists() && parentFile.isDirectory() ) { return FileUtil.createNewFile( file ); } else { if ( FileUtil.createDirectory( parentFile.getAbsolutePath() ) ) { return FileUtil.createNewFile( file ); } else { logger.error( "In createNewFile, failed to create parent directory '{}' for creating file '{}'.", parentFile.getAbsolutePath(), fileAbsPath ); return false; } } } private  FileUtil(); static boolean isFileExists( final String dirAbsPath, final String fileName ); static boolean isFileExists( final String fileAbsPath ); static boolean isDirExists( final String dirAbsPath ); static File[] findFiles( final String dirAbsPath, final String ext ); static boolean setFilesExecutable( final String dirAbsPath, final String ext ); static boolean extractArchive( final String archiveFileAbsPath, final String destDirAbsPath ); static boolean extractArchive( final File archiveFile, final File destDir ); static File[] findFiles( final String dirAbsPath, final String[] extensions, boolean recursive ); static File[] findFiles( final File dirAbsPath, final String[] extensions, boolean recursive ); static File[] findFiles( final String dirAbsPath, final String fileNamePattern, boolean recursive ); static String getFileChecksum( final String fileAbsPath, ChecksumMethod checksumMethod ); static boolean deleteDirectory( final String directory ); static boolean deleteDirectory( final File directory ); static String getTemporaryFolderPath(); static boolean deleteFile( final String filePath ); static boolean createDirectory( final String dirPath ); static String getFileBaseName( final String fileName ); static boolean unzipFile( final String zipFileAbsPath, final String outputDirAbsPath ); static boolean createOrUpdateFile( final String filePath, final String fileContent ); static boolean createOrUpdateFile( final String filePath, final String fileContent,
                                              final boolean createBackup ); static boolean createNewFile( final String fileAbsPath ); static String readFileToString( final String fileName ); static String findLatestFileByLastModified( final String directory, final String fileNamePattern,
                                                       final boolean recursive );  }
@Test public void testCreateNewFile() { final String fileAbsPath = FilenameUtils.concat( tmpDir, this.getDateTimeInMillis() + ".txt" ); boolean created = FileUtil.createNewFile( fileAbsPath ); assertTrue( created ); assertTrue( FileUtil.isFileExists( fileAbsPath ) ); assertTrue( FileUtil.deleteFile( fileAbsPath ) ); }