📄 filedeal.java
字号:
package cumt.file;
import java.io.*;
import java.util.regex.Pattern;
public class FileDeal {
public static boolean isEmpty(String s){
if(s==null)
return false;
else{
s=s.trim();
return s.equals("");
}
}
public static String convertToCN(String s){
try{
return s==null?"":new String( s.toString().getBytes("8859_1"),"gbk" );
}catch(Exception e){
return "";
}
}
public static boolean isValidName(String s){
if(s==null)
return false;
else{
String str="[#】\\[\\]\\s\"']+";
return !Pattern.matches(str, s);
}
}
public static boolean exists(String path){
File file=new File(path);
return file.exists();
}
public static boolean delete(String path){
File file=new File(path);
if( file.exists()){
if(file.isDirectory()){
File files[]=file.listFiles();
for(int i=0;i<files.length;i++){
delete(path+"/"+files[i].getName());
}
return file.delete();
}
else
return file.delete();
}
else
return true;
}
public static boolean isDirectory(String path){
File file=new File(path);
return file.isDirectory();
}
public static boolean isFile(String path){
File file=new File(path);
return file.isFile();
}
public static boolean replace(String path,File temp){
File file=new File(path);
if(delete(path)){
temp.renameTo(file);
return true;
}else
return false;
}
public static boolean createFolder(String path) throws IOException{
if(!isValidName(path))
return false;
File file=new File(path);
if(!file.exists()){
return file.mkdir();
}else
return false;
}
public static boolean rename(String path,String dest){
File file=new File(path);
if(file.exists() && isValidName(dest)){
try{
return file.renameTo(new File(file.getParent()+"\\"+dest));
}catch(Exception e){
return false;
}
}
return false;
}
}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -