Main.java Source code

Java tutorial

Introduction

Here is the source code for Main.java

Source

//package com.java2s;
//License from project: Apache License 

import java.io.File;

import android.text.TextUtils;

public class Main {

    public static boolean rename(String oldName, String newName, boolean delNewFile) {
        File oldFile = new File(oldName);
        File newFile = new File(newName);

        if (!oldFile.exists()) {
            return false;
        }

        boolean result = true;
        if (newFile.exists()) {
            if (delNewFile) {
                result = deleteFile(newName);
            }
        }

        if (result && oldFile.renameTo(newFile)) {
            return true;
        }
        return false;
    }

    public static boolean deleteFile(final String fileName) {
        if (TextUtils.isEmpty(fileName)) {
            return false;
        }

        boolean result = false;
        File file = new File(fileName);
        if (file.isFile() && file.exists()) {
            result = file.delete();
        }
        return result;
    }
}