2 * Svjatoslav Commons - shared library of common functionality. Author: Svjatoslav Agejenko.
3 * This project is released under Creative Commons Zero (CC0) license.
5 package eu.svjatoslav.commons.file;
9 public class FilePathParser {
11 public static String getFileExtension(final File file) {
12 final String fullFileName = file.getName();
14 return getFileExtension(fullFileName);
17 public static String getFileExtension(final String fullFileName) {
18 final int dot = fullFileName.lastIndexOf('.');
23 fileExtension = fullFileName.substring(dot + 1);
24 fileExtension = fileExtension.toLowerCase();
30 public static String getFileNameWithoutExtension(final File file) {
31 final String fullFileName = file.getName();
32 return getFileNameWithoutExtension(fullFileName);
35 public static String getFileNameWithoutExtension(final String fullFileName) {
36 final int dot = fullFileName.lastIndexOf('.');
39 fileName = fullFileName;
41 fileName = fullFileName.substring(0, dot);
46 public static String getFileSizeDescription(long fileSize) {
49 if (fileSize > (1024 * 1024 * 10)) {
50 fileSize = fileSize / (1024 * 1024);
52 } else if (fileSize > (1024 * 10)) {
53 fileSize = fileSize / 1024;
57 return String.valueOf(fileSize) + " " + suffix;