?? dealfile.java
字號:
package com.onlinestudy.service;
import java.io.File;
import java.util.Random;
import org.apache.struts.upload.FormFile;
public class DealFile {
/**
* 判斷照片類型 .jpg .png .gif 目前只支持這三種格式
* @param file
* @return
*/
public static boolean isPhoto(FormFile file) {
String fileName = getString(file.getFileName());
if (fileName.equals(""))
return false;
if ((fileName.toLowerCase().endsWith(".jpg"))
|| (fileName.toLowerCase().endsWith(".gif"))
|| (fileName.toLowerCase().endsWith(".png")))
return true;
else
return false;
}
/**
*
* @param str
* @return
*/
public static String getString(String str) {
if (str == null)
str = "";
if (str.equals("null"))
str = "";
str = str.trim();
return str;
}
/**
* 判斷文件是否存在
* @param fileName
* @param dir
* @return
*/
public static boolean isFileExist(String fileName, String dir) {
File files = new File(dir + fileName);
return (files.exists()) ? true : false;
}
/**
* 重命名
* @param fileName
* @param dir
*/
public static String rename(String fileName, String dir) {
Random random = new Random();
int add = random.nextInt(10000);
String ret = add+fileName;
while (isFileExist(ret, dir)) {
add = random.nextInt(10000);
ret = add + fileName;
}
return ret;
}
public static boolean isGif(String file) {
if (file.toLowerCase().endsWith(".gif")) {
return true;
} else {
return false;
}
}
public static boolean isJpg(String file) {
if (file.toLowerCase().endsWith(".jpg")) {
return true;
} else {
return false;
}
}
public static boolean isPng(String file) {
if (file.toLowerCase().endsWith(".png")) {
return true;
} else {
return false;
}
}
}
?? 快捷鍵說明
復制代碼
Ctrl + C
搜索代碼
Ctrl + F
全屏模式
F11
切換主題
Ctrl + Shift + D
顯示快捷鍵
?
增大字號
Ctrl + =
減小字號
Ctrl + -