Skip to content

Commit c2ef2ab

Browse files
committed
add FileUtils
1 parent 4fffeae commit c2ef2ab

File tree

6 files changed

+567
-7
lines changed

6 files changed

+567
-7
lines changed

.idea/misc.xml

Lines changed: 1 addition & 1 deletion
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

README.md

Lines changed: 20 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,26 @@ taoyuan's AndroidUtils
1717
```
1818

1919
2. app build.gradle下添加依赖
20-
`compile 'com.github.seeways:AndroidUtils:1.1.7'`
20+
`compile 'com.github.seeways:AndroidUtils:1.1.8'`
21+
22+
# 2017.3.22
23+
新增FileUtils
24+
25+
- 文件工具类 FileUtils
26+
+ 根据文件路径获取文件 `File getFileByPath(String filePath)`
27+
+ 判断文件是否存在 `boolean isFileExists(String filePath)`
28+
+ 重命名文件 `boolean renameFile(String filePath, String newName)`
29+
+ 判断是否是目录 `boolean isDir(String dirPath)`
30+
+ 判断是否是文件 `boolean isFile(String filePath)`
31+
+ 如果目录不存在则创建 `boolean createOrExistsDir(String dirPath)`
32+
+ 获取目录下制定后缀名的文件(忽略大小写) `List<File> listFilesInDirWithFilter(String dirPath, String suffix, boolean isRecursive)`
33+
+ 文件转bytes `byte[] File2Bytes(String filePath)`
34+
+ 获取文件大小 `String getFileSize(String PathOrURL)`
35+
+ 获取文件长度 `long getFileLength(String filePath)`
36+
+ 获取文件名 `String getFileName(String filePath)`
37+
+ 获取拓展名 `String getFileExtension(String filePath)`
38+
39+
2140

2241
# 2017.3.20
2342
新增EncodeUtils,EncryptUtils,StringUtils
Lines changed: 34 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,34 @@
1+
package com.jty.myutils.constant;
2+
3+
/**
4+
* @author TaoYuan
5+
* @time 2017/3/22 0022
6+
* @desc
7+
*/
8+
9+
public class MemoryUtils {
10+
/******************** 存储相关常量 ********************/
11+
/**
12+
* Byte与Byte的倍数
13+
*/
14+
public static final int BYTE = 1;
15+
/**
16+
* KB与Byte的倍数
17+
*/
18+
public static final int KB = 1024;
19+
/**
20+
* MB与Byte的倍数
21+
*/
22+
public static final int MB = 1048576;
23+
/**
24+
* GB与Byte的倍数
25+
*/
26+
public static final int GB = 1073741824;
27+
28+
public enum MemoryUnit {
29+
BYTE,
30+
KB,
31+
MB,
32+
GB
33+
}
34+
}
Lines changed: 104 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,104 @@
1+
package com.jty.myutils.constant;
2+
3+
/**
4+
* @author TaoYuan
5+
* @time 2017/3/22 0022
6+
* @desc Regex
7+
*/
8+
9+
public class RegexUtils {
10+
11+
/**
12+
* 正则:手机号(简单)
13+
*/
14+
public static final String REGEX_MOBILE_SIMPLE = "^[1]\\d{10}$";
15+
/**
16+
* 正则:手机号(精确)
17+
* <p>移动:134(0-8)、135、136、137、138、139、147、150、151、152、157、158、159、178、182、183、184、187、188</p>
18+
* <p>联通:130、131、132、145、155、156、175、176、185、186</p>
19+
* <p>电信:133、153、173、177、180、181、189</p>
20+
* <p>全球星:1349</p>
21+
* <p>虚拟运营商:170</p>
22+
*/
23+
public static final String REGEX_MOBILE_EXACT = "^((13[0-9])|(14[5,7])|(15[0-3,5-9])|(17[0,3,5-8])|(18[0-9])|(147))\\d{8}$";
24+
/**
25+
* 正则:电话号码
26+
*/
27+
public static final String REGEX_TEL = "^0\\d{2,3}[- ]?\\d{7,8}";
28+
/**
29+
* 正则:身份证号码18位
30+
*/
31+
public static final String REGEX_ID_CARD18 = "^[1-9]\\d{5}[1-9]\\d{3}((0\\d)|(1[0-2]))(([0|1|2]\\d)|3[0-1])\\d{3}([0-9Xx])$";
32+
/**
33+
* 正则:邮箱
34+
*/
35+
public static final String REGEX_EMAIL = "^\\w+([-+.]\\w+)*@\\w+([-.]\\w+)*\\.\\w+([-.]\\w+)*$";
36+
/**
37+
* 正则:URL
38+
*/
39+
public static final String REGEX_URL = "[a-zA-z]+://[^\\s]*";
40+
/**
41+
* 正则:汉字
42+
*/
43+
public static final String REGEX_ZH = "^[\\u4e00-\\u9fa5]+$";
44+
/**
45+
* 正则:用户名,取值范围为a-z,A-Z,0-9,"_",汉字,不能以"_"结尾,用户名必须是6-20位
46+
*/
47+
public static final String REGEX_USERNAME = "^[\\w\\u4e00-\\u9fa5]{6,20}(?<!_)$";
48+
/**
49+
* 正则:yyyy-MM-dd格式的日期校验,已考虑平闰年
50+
*/
51+
public static final String REGEX_DATE = "^(?:(?!0000)[0-9]{4}-(?:(?:0[1-9]|1[0-2])-(?:0[1-9]|1[0-9]|2[0-8])|(?:0[13-9]|1[0-2])-(?:29|30)|(?:0[13578]|1[02])-31)|(?:[0-9]{2}(?:0[48]|[2468][048]|[13579][26])|(?:0[48]|[2468][048]|[13579][26])00)-02-29)$";
52+
/**
53+
* 正则:IP地址
54+
*/
55+
public static final String REGEX_IP = "((2[0-4]\\d|25[0-5]|[01]?\\d\\d?)\\.){3}(2[0-4]\\d|25[0-5]|[01]?\\d\\d?)";
56+
57+
/************** 以下摘自http://tool.oschina.net/regex **************/
58+
/**
59+
* 正则:双字节字符(包括汉字在内)
60+
*/
61+
public static final String REGEX_DOUBLE_BYTE_CHAR = "[^\\x00-\\xff]";
62+
/**
63+
* 正则:空白行
64+
*/
65+
public static final String REGEX_BLANK_LINE = "\\n\\s*\\r";
66+
/**
67+
* 正则:QQ号
68+
*/
69+
public static final String REGEX_TENCENT_NUM = "[1-9][0-9]{4,}";
70+
/**
71+
* 正则:中国邮政编码
72+
*/
73+
public static final String REGEX_ZIP_CODE = "[1-9]\\d{5}(?!\\d)";
74+
/**
75+
* 正则:正整数
76+
*/
77+
public static final String REGEX_POSITIVE_INTEGER = "^[1-9]\\d*$";
78+
/**
79+
* 正则:负整数
80+
*/
81+
public static final String REGEX_NEGATIVE_INTEGER = "^-[1-9]\\d*$";
82+
/**
83+
* 正则:整数
84+
*/
85+
public static final String REGEX_INTEGER = "^-?[1-9]\\d*$";
86+
/**
87+
* 正则:非负整数(正整数 + 0)
88+
*/
89+
public static final String REGEX_NOT_NEGATIVE_INTEGER = "^[1-9]\\d*|0$";
90+
/**
91+
* 正则:非正整数(负整数 + 0)
92+
*/
93+
public static final String REGEX_NOT_POSITIVE_INTEGER = "^-[1-9]\\d*|0$";
94+
/**
95+
* 正则:正浮点数
96+
*/
97+
public static final String REGEX_POSITIVE_FLOAT = "^[1-9]\\d*\\.\\d*|0\\.\\d*[1-9]\\d*$";
98+
/**
99+
* 正则:负浮点数
100+
*/
101+
public static final String REGEX_NEGATIVE_FLOAT = "^-[1-9]\\d*\\.\\d*|-0\\.\\d*[1-9]\\d*$";
102+
103+
/************** If u want more please visit http://toutiao.com/i6231678548520731137/ **************/
104+
}

0 commit comments

Comments
 (0)