wxr
2022-11-23 1e7b3abd15d37f6c6bc97ac14922457b9604c275
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
package com.mm.android.deviceaddmodule.utils;
 
 
import android.content.Context;
 
 
import java.io.File;
import java.io.FileInputStream;
import java.io.FileOutputStream;
import java.io.IOException;
import java.io.InputStream;
import java.io.OutputStream;
 
/**
 * Created by 32716 on 2017/5/19.
 */
public class FileHelper {
 
 
 
    public static boolean isMP4File(String path) {
        if (path.toLowerCase().endsWith(".mp4") ||
                path.toLowerCase().contains(".mp4")) {
            return true;
        }
        return false;
    }
 
    /**
     * 重命名文件
     *
     * @param oldFile
     * @param newFile
     * @return
     */
    public static boolean renameFile(File oldFile, File newFile) {
        if (oldFile.exists()) {
            if (newFile.exists()) {
                newFile.delete();
            }
            return oldFile.renameTo(newFile);
        } else {
            return false;
        }
    }
 
    private static File getDataBaseFile(Context context, String dataBaseName) {
        String dataBasePath = context.getApplicationContext().getDatabasePath(dataBaseName).getPath();
        return new File(dataBasePath);
    }
 
    public static boolean updateDataBaseName(Context context, String oldName, String newName) {
        File oldDataBaseFile = getDataBaseFile(context, oldName);
        File newDataBaseFile = getDataBaseFile(context, newName);
        return renameFile(oldDataBaseFile, newDataBaseFile);
    }
}