Pu Zhibing
2025-03-16 6aa6dc075078cca11be048a267911bd7f74dadcd
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
package com.panzhihua.sangeshenbian.utils;
 
import java.io.File;
import java.io.InputStream;
 
public class FileUtil {
    public static InputStream getResourcesFileInputStream(String fileName) {
        return Thread.currentThread().getContextClassLoader().getResourceAsStream("" + fileName);
    }
 
    public static String getPath() {
        return FileUtil.class.getResource("/").getPath();
    }
 
    public static File createNewFile(String pathName) {
        File file = new File(getPath() + pathName);
        if (file.exists()) {
            file.delete();
        } else {
            if (!file.getParentFile().exists()) {
                file.getParentFile().mkdirs();
            }
        }
        return file;
    }
 
    public static File readFile(String pathName) {
        return new File(getPath() + pathName);
    }
 
    public static File readUserHomeFile(String pathName) {
        return new File(System.getProperty("user.home") + File.separator + pathName);
    }
}