读取db.properties文件
/**
* 读取properties配置文件
* @return
*/
public static String readProperties(String fileName,String key){
String value = "";
InputStream in = null;
try {
Properties props = new Properties();
in = FileUtil.class.getResourceAsStream(fileName);
props.load(in);
value = props.getProperty(key);
} catch (IOException e) {
e.printStackTrace();
return "";
}finally {
try {
in.close();
} catch (IOException e) {
}
}
return value;
}
获取文件类型
/**
* 获取文件的类型。 文件名中最后一个"."后面的部分。
* @param fileName
* @return
*/
public static String getTypePart(String fileName){
int point = fileName.lastIndexOf(".");
String fileType = fileName.substring(point + 1);
if (point == -1 || point == fileName.length() - 1) {
return "无此类型";
}
return fileType;
}
删除文件夹以及文件夹下面的所有文件
/**
* 删除文件夹以及下面的所有文件
* @param delPath
* @return
*/
public static boolean deleteFile(String delPath){
try {
File file = new File(delPath);
if(!file.isDirectory()){
file.delete();
}else if(file.isDirectory()){
String[] fileList = file.list();
for(int i=0; i<fileList.length; i++){
String tempFilePath = delPath + File.separator + fileList[i];
File delFile = new File(tempFilePath);
if(!delFile.isDirectory()){
delFile.delete();
}else{
deleteFile(tempFilePath);
}
}
if (file.listFiles().length <= 0) {
file.delete();
}
}
} catch (Exception e) {
e.printStackTrace();
return false;
}
return true;
}