Java Utililty Methods File Name Create

List of utility methods to do File Name Create

Description

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

Method

StringfileName(String filename)
file Name
String name = "";
int i = filename.lastIndexOf('.');
int p = Math.max(filename.lastIndexOf('/'), filename.lastIndexOf('\\'));
if (i > p) {
    name = filename.substring(0, i);
return name;
Stringfilename(String filename)
filename
return filename.replaceFirst("^~/", System.getProperty("user.home") + "/");
StringfileName(String name)
Return filename sans extension.
String fname = pathName(name);
int index = name.indexOf(".");
if (index > 0)
    fname = fname.substring(0, index);
return fname;
Stringfilename(String name)
filename
final String basename = basename(name);
final int idx = basename.indexOf('.');
if (idx >= 0 && idx < basename.length()) {
    return basename.substring(0, idx);
return name;
Stringfilename(String name, String ext)
Simply concatenates name with extension using dot.
return name + "." + ext;
StringfileName(String path)
returns the filename from the given path
int pos = Math.max(path.lastIndexOf('/'), path.lastIndexOf('\\'));
if (pos > 0) {
    return path.substring(pos + 1);
return path;
StringfileName(String path)
extract a file name from 'path'
path = normalize(path);
return path.substring(path.lastIndexOf('/') + 1);
StringfileName(String path)
file Name
if (path.endsWith("/")) {
    throw new IllegalArgumentException("path cannot end with a slash");
int indexOfLastSeparator = path.lastIndexOf('/');
if (indexOfLastSeparator == -1) {
    throw new IllegalArgumentException("path does not contain any slashes");
return path.substring(indexOfLastSeparator + 1);
...
Stringfilename(String prefix, String sep, String index)
Construct a filename
return String.format("%s%s%s", prefix, sep, index);
StringFileName(String[] args)
File Name
String name = null;
for (int i = 0; i < args.length; i++) {
    if (i == 0) {
        name = args[i];
    } else {
        name = name + "_" + args[i];
return name.toLowerCase() + ".txt";