|
@@ -1,5 +1,7 @@
|
|
|
package cn.com.qmth.examcloud.commons.util;
|
|
|
|
|
|
+import org.apache.commons.lang3.StringUtils;
|
|
|
+
|
|
|
import java.io.File;
|
|
|
import java.util.Arrays;
|
|
|
import java.util.Comparator;
|
|
@@ -13,24 +15,40 @@ import java.util.Comparator;
|
|
|
*/
|
|
|
public class FileUtil {
|
|
|
|
|
|
- /**
|
|
|
- * 排序
|
|
|
- *
|
|
|
- * @author WANGWEI
|
|
|
- * @param files
|
|
|
- */
|
|
|
- public static void sortByLastUpdateTime(File... files) {
|
|
|
- Arrays.sort(files, new Comparator<File>() {
|
|
|
- public int compare(File f1, File f2) {
|
|
|
- long diff = f1.lastModified() - f2.lastModified();
|
|
|
- if (diff > 0)
|
|
|
- return 1;
|
|
|
- else if (diff == 0)
|
|
|
- return 0;
|
|
|
- else
|
|
|
- return -1;
|
|
|
- }
|
|
|
- });
|
|
|
- }
|
|
|
+ /**
|
|
|
+ * 排序
|
|
|
+ *
|
|
|
+ * @param files
|
|
|
+ * @author WANGWEI
|
|
|
+ */
|
|
|
+ public static void sortByLastUpdateTime(File... files) {
|
|
|
+ Arrays.sort(files, new Comparator<File>() {
|
|
|
+ public int compare(File f1, File f2) {
|
|
|
+ long diff = f1.lastModified() - f2.lastModified();
|
|
|
+ if (diff > 0)
|
|
|
+ return 1;
|
|
|
+ else if (diff == 0)
|
|
|
+ return 0;
|
|
|
+ else
|
|
|
+ return -1;
|
|
|
+ }
|
|
|
+ });
|
|
|
+ }
|
|
|
+
|
|
|
+ /**
|
|
|
+ * 获取文件后缀名,包括"."
|
|
|
+ */
|
|
|
+ public static String getFileSuffix(String fileName) {
|
|
|
+ if (StringUtils.isEmpty(fileName)) {
|
|
|
+ return "";
|
|
|
+ }
|
|
|
+
|
|
|
+ int index = fileName.lastIndexOf(".");
|
|
|
+ if (index > 0) {
|
|
|
+ return fileName.substring(index).toLowerCase();
|
|
|
+ }
|
|
|
+
|
|
|
+ return "";
|
|
|
+ }
|
|
|
|
|
|
}
|