Java Rename File renameFileFromChinese(File file)

Here you can find the source of renameFileFromChinese(File file)

Description

rename File From Chinese

License

Open Source License

Declaration

public static File renameFileFromChinese(File file) 

Method Source Code

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

import java.io.File;

public class Main {
    public static File renameFileFromChinese(File file) {
        String fileName = file.getName();
        String extension = getExtension(fileName);
        String destFileName = fileName.substring(0, fileName.lastIndexOf(File.separator) + 1)
                + System.currentTimeMillis() + extension;
        File destFile = new File(destFileName);
        file.renameTo(destFile);//from  w  w  w  .  j  av  a  2s. c o m
        return destFile;
    }

    public static String getExtension(String fileName) {
        if (fileName != null && fileName.length() > 0) {
            int i = fileName.lastIndexOf('.');
            if (i > -1 && i < fileName.length()) {
                return fileName.substring(i + 1, fileName.length());
            }
        }
        return fileName;
    }
}

Related

  1. renameExistingWithRetries(final File fromFile, final File toFile)
  2. renameFile(File src, File dest)
  3. renameFile(String source, String dest)
  4. renameFile(String sourcePath, String targetPath)
  5. renameFile(String src_pathname, String dest_pathname)
  6. renameFileHard(File srcFile, File destFile)
  7. renameFileIfExists(File f)
  8. renameFileOnWindows(File oldFile, File newFile)
  9. renameFiles(File fileDirectory, String regex, String replacement)