Java File Path Create filePathGen(String oldPath, String newExtension, String newFileName)

Here you can find the source of filePathGen(String oldPath, String newExtension, String newFileName)

Description

Create a copy of a file in same directory but can rename and change it's extension

License

Open Source License

Parameter

Parameter Description
oldPath a parameter
newExtension a parameter
newFileName a parameter

Return

String newPath

Declaration

public static String filePathGen(String oldPath, String newExtension, String newFileName) 

Method Source Code

//package com.java2s;
//License from project: Open Source License 

public class Main {
    /**/*w ww. jav a 2s . c o m*/
     * Create a copy of a file in same directory but can rename and change it's
     * extension
     * 
     * @param oldPath
     * @param newExtension
     * @param newFileName
     * @return String newPath
     */
    public static String filePathGen(String oldPath, String newExtension, String newFileName) {
        if (newFileName.contains(".")) {
            newFileName = newFileName.substring(0, newFileName.lastIndexOf('.'));
        }

        if (newExtension.charAt(0) != '.') {
            newExtension = "." + newExtension;
        }

        String newPath = "";
        if (newFileName != null) {
            newPath = oldPath.substring(0, oldPath.lastIndexOf('\\') + 1) + newFileName + newExtension;
        } else {
            newPath = oldPath.substring(0, oldPath.lastIndexOf('.')) + newExtension;
        }

        return newPath;
    }
}

Related

  1. filePath(String compchartimage)
  2. filePath(String dirPath, String fileName)
  3. filePath2PackageName(String entryName)
  4. filePathBlackList(String value)
  5. filePathCheck(final String filePath)
  6. filePathJava(String path)