反转一个字符串和删除N层级目录的所有文件或者删除数据库所有表保留数据库;清除数据库所有表的数据

版权声明:本文为博主原创文章,未经博主允许不得转载。 https://blog.csdn.net/firewolf1758/article/details/61205435

1、反转一个字符例如“123”反转为"321";

public static String convertString(String item){

StringBuffer stringBuffer = new StringBuffer();
if(StringUtil.isNotEmpty(item)){
int length = item.length();
for(int i=length-1;i>=0;i--){
stringBuffer.append(item.charAt(i));
}
return stringBuffer.toString();
}else{
return null;
}
}

2、删除某个路径下的N层级目录的所有文件
public static void deleteFile(String path){
File file = new File(path);
if(FileUtil.exists(path)){
File[] childFiles = file.listFiles();
for(File childFile:childFiles){
if(childFile.isFile()){
FileUtil.delete(childFile);
}else if(childFile.isDirectory()){
deleteFile(childFile.getAbsolutePath());
}
}
}

}

3、删除数据库所有表保留数据库,或者清除数据库所有表的数据;

SELECT CONCAT('drop table ',table_name,';') FROM information_schema.`TABLES` WHERE table_schema='数据库名';

SELECT CONCAT('truncate table ',table_name,';') FROM information_schema.`TABLES` WHERE table_schema='数据库名';

猜你喜欢

转载自blog.csdn.net/firewolf1758/article/details/61205435