Android Utililty Methods File Name Get

List of utility methods to do File Name Get

Description

The list of methods to do File Name Get are organized into topic(s).

Method

StringgetFileName(String fileName)
Recebe o nome do arquivo e retorna seu conteudo, removendo a extensao: teste.txt -> teste arquivo para rename -> arquivo para rename outro_teste.comPonto.xls -> outro_teste.comPonto
if (fileName == null) {
    return null;
if (fileName.equals("")) {
    return "";
String[] valores = fileName.split("\\.");
if (valores.length == 1) {
...
StringgetFileName(String filePath)
get File Name
if (StringUtil.isEmpty(filePath)) {
    return null;
int pos = filePath.lastIndexOf(File.separator);
if (pos == -1) {
    return null;
return filePath.substring(pos + 1);
...
StringgetFileName(String path)
Return the filename component of the provided string path, if one exists.
if (!isLikelyFilePath(path)) {
    return null;
String[] components = path.split("\\\\|/"); 
return components[components.length - 1];
StringgetRandomFileName(String prefix, String suffix)
Creates a file name with a random integer number inserted between the prefix and suffix
StringBuilder name = new StringBuilder();
if (prefix != null) {
    name.append(prefix);
name.append((long) (Integer.MAX_VALUE * Math.random()));
if (suffix != null) {
    name.append(suffix);
return name.toString();
StringparseFileName(String path)
Returns the filename or last name in the path.
String fileName = null;
if (path != null) {
    String[] parts = path.split("[/|\\\\]");
    fileName = parts[parts.length - 1];
return fileName;
StringgetSuffix(File file)
Returns a suffix string from a File.
String filename = file.getName();
int index = filename.lastIndexOf(".");
if (index != -1) {
    return filename.substring(index + 1);
return filename;
StringgetSuffix(String fileName)
get Suffix
if (!TextUtils.isEmpty(fileName) && fileName.contains(".")) {
    return fileName.substring(fileName.lastIndexOf(".") + 1);
return "";
StringgetNamePart(String fileName)
get Name Part
int point = getPathLastIndex(fileName);
int length = fileName.length();
if (point == -1) {
    return fileName;
} else if (point == length - 1) {
    int secondPoint = getPathLastIndex(fileName, point - 1);
    if (secondPoint == -1) {
        if (length == 1) {
...
FileappendNumberToFilenameIfExists(String fileName, File directory)
append Number To Filename If Exists
File newFile = new File(directory, fileName);
int nextFile = 0;
while (newFile.exists()) {
    nextFile++;
    newFile = new File(directory, fileName + " ("
            + Integer.toString(nextFile) + ")");
return newFile;
...
StringgetUniqueImageFilename(String prefix)
get Unique Image Filename
String timeStamp = new SimpleDateFormat("yyyyMMdd_HHmmss")
        .format(new Date());
String imageFileName = prefix + timeStamp + ".jpg";
return imageFileName;