java对文件操作--01
2024-10-12 19:28:01
1、删除文件
/**
* delete file
* 删除文件
* @param fileName
* @return
*/
private boolean deleteDir(String fileName)
{
boolean flag = false;
File file = new File(fileName);
if(file.exists()){
flag = delFile(file);
} return flag;
} /**
* delete file
* 删除文件
* @param fileName
* @return
*/
private boolean delFile(File file) {
if (!file.exists()) {
return false;
} if (file.isDirectory()) {
File[] files = file.listFiles();
for (File f : files) {
delFile(f);
}
}
return file.delete();
}
2、获取项目根路径
/**
* 获取路径
* @return
*/
public String getWebRoot()
{
String realUrl = getClass().getProtectionDomain().getCodeSource()
.getLocation().getPath(); String newUrl = ""; if (realUrl.contains("/WEB-INF/"))
{
newUrl = realUrl.substring(, realUrl.lastIndexOf("WEB-INF/"));
} realUrl = newUrl.replace("%20", " ");//此路径不兼容jboss return realUrl;
}
最新文章
- 用powershell批量新增user profile
- LeetCode:Find the Difference_389
- jQuery的事件委托实例分析
- ASP.NET MVC Web API 学习笔记---第一个Web API程序
- 转:纠结的Shim
- Android线程管理(三)——Thread类的内部原理、休眠及唤醒
- redmine一键安装
- 二模08day1解题报告
- HA集群heartbeat配置--Nginx
- Database Design Guidelines
- Python01(linux基础)
- mssql 怎么配置指定的表 不允许删除数据?
- 【演变】Ajax(AjAj)到WebSocket
- Unity调试模式设置辅助线是否可见
- [ERROR] Failed to execute goal org.codehaus.mojo:gwt-maven-plugin:2.5.0-rc1:compile (default) on project zeus-web: Command 解决
- 向eclipse的JavaWeb项目中导入jar包
- 使用ant优化android项目编译速度,提高工作效率
- Prime Ring Problem dfs
- js往div里添加table
- PlSQL Oracle 中的 对应 SQL server 中的 IsNull(Expr1,Expr2)