public int renameFile(String file, String toFile) {
        File toBeRenamed = new File(file);

        if ((!(toBeRenamed.exists())) || (toBeRenamed.isDirectory())) {
            System.out.println("File does not exist: " + file);
            return 0;
        }

        File newFile = new File(toFile);

        if (toBeRenamed.renameTo(newFile)) {
            System.out.println("File has been renamed.");
            return 1;
        }
        System.out.println("Error renmaing file");
        return -1;
    }

 

posted on 2017-03-14 18:07  悲伤穿透眼眸  阅读(201)  评论(0编辑  收藏  举报