Project

General

Profile

Statistics
| Revision:

root / src / utils / Utils.java @ 2

History | View | Annotate | Download (1.21 KB)

1
package utils;
2

    
3
import java.io.File;
4
import java.io.IOException;
5

    
6
/**
7
 * Utils
8
 */
9
public class Utils {
10

    
11
    public static boolean isInteger(String s) {
12
        if (s.isEmpty())
13
            return false;
14
        for (int i = 0; i < s.length(); i++) {
15
            if (i == 0 && s.charAt(i) == '-') {
16
                if (s.length() == 1)
17
                    return false;
18
                else
19
                    continue;
20
            }
21
            if (Character.digit(s.charAt(i), 10) < 0)
22
                return false;
23
        }
24
        return true;
25
    }
26

    
27
    public static boolean fileExists(String filePath) {
28
        return new File(filePath).isFile();
29
    }
30

    
31
    public static boolean isFloat(String s) {
32
        return s.matches("[0-9]*\\.?[0-9]+");
33
    }
34

    
35
    public static boolean deleteDirectoryRecursively(File file) /*throws IOException */{
36
        
37
        File[] files = file.listFiles();
38
        if(files!=null) {
39
            for(File f: files) {
40
                if(f.isDirectory()) {
41
                    deleteDirectoryRecursively(f);
42
                } else {
43
                    f.delete();
44
                }
45
            }
46
        }
47
        return file.delete();
48
    }
49
}