mirror of
https://codeberg.org/OpenTracksApp/OpenTracks.git
synced 2026-10-08 20:33:06 +02:00
Code cleanup: add getExtension and getName in FileUtils.java
This commit is contained in:
@@ -144,6 +144,32 @@ public class FileUtils {
|
||||
return buildUniqueFileName(directory, fileBaseName, extension, 0);
|
||||
}
|
||||
|
||||
/**
|
||||
* Gets the name from a file name, without the extension.
|
||||
*
|
||||
* @param fileName the file name
|
||||
*/
|
||||
public static String getName(String fileName) {
|
||||
int index = fileName.lastIndexOf('.');
|
||||
if (index == -1) {
|
||||
return fileName;
|
||||
}
|
||||
return fileName.substring(0, index);
|
||||
}
|
||||
|
||||
/**
|
||||
* Gets the extension from a file name. Returns null if there is no extension.
|
||||
*
|
||||
* @param fileName the file name
|
||||
*/
|
||||
public static String getExtension(String fileName) {
|
||||
int index = fileName.lastIndexOf('.');
|
||||
if (index == -1) {
|
||||
return null;
|
||||
}
|
||||
return fileName.substring(index + 1);
|
||||
}
|
||||
|
||||
/**
|
||||
* Builds a filename with the given base and the given extension, possibly
|
||||
* adding a suffix to ensure the file doesn't exist.
|
||||
|
||||
Reference in New Issue
Block a user