66
77public class FileUtils {
88
9+ /**
10+ * Verifica se a extensao de um arquivo corresponde a informada por parametro
11+ *
12+ * @param file Arquivo
13+ * @param extennsionName Extensao a ser verificada
14+ * @return {@code boolean}
15+ */
916 public static boolean checkExtensionName (File file , String extennsionName ) {
1017 if (isNull (file )) {
1118 return false ;
@@ -14,19 +21,45 @@ public static boolean checkExtensionName(File file, String extennsionName) {
1421 return extensionOpt .isPresent () && extensionOpt .get ().equals (extennsionName );
1522 }
1623
24+ /**
25+ * Retorna um novo arquivo com o mesmo nome do arquivo informado e com uma extensao diferente
26+ *
27+ * @param file Arquivo
28+ * @param extension Nova extensao
29+ * @return {@code File}
30+ */
1731 public static File changeExtension (File file , String extension ) {
1832 String filename = _getFileNameWithoutExtension (file ) + "." + extension ;
1933 return new File (file .getParent (), filename );
2034 }
2135
36+ /**
37+ * Retorna um novo arquivo com o mesmo nome do arquivo informado concatenando uma nova extensao
38+ *
39+ * @param file Arquivo
40+ * @param extension Extensao a ser concatenada
41+ * @return {@code File}
42+ */
2243 public static File appendExtension (File file , String extension ) {
2344 return new File (file .getParent (), file .getName () + "." + extension );
2445 }
2546
47+ /**
48+ * Retorna um novo arquivo com o mesmo nome do arquivo informado sem extensao
49+ *
50+ * @param file Arquivo
51+ * @return {@code File}
52+ */
2653 public static File removeExtension (File file ) {
2754 return new File (file .getParent (), _getFileNameWithoutExtension (file ));
2855 }
2956
57+ /**
58+ * Retorna a extensao do arquivo a partir do seu nome
59+ *
60+ * @param filename Nome do arquivo
61+ * @return {@code Optional<String>}
62+ */
3063 public static Optional <String > getFileExtension (String filename ) {
3164 return Optional .ofNullable (filename )
3265 .filter (f -> f .contains ("." ))
0 commit comments