任何人都可以提出任何想法如何从代码中创建 java web 应用程序的项目结构中的文件夹吗?
问问题
6787 次
3 回答
2
您正在谈论在 servletcontainer/webappContext.. 中创建一个文件夹。这是如何做到的:
public void doPost(HttpServletRequest req,HttpServletResponse resp){
String path = req.getServletContext().getRealPath("/");
File f = new File (path +"myNewFolder");
f.mkdir();
}
于 2013-10-24T08:37:22.977 回答
1
发现这个:
File f = new File("C:\\Test");
try{
if(f.mkdir()) {
System.out.println("Directory Created");
} else {
System.out.println("Directory is not created");
}
} catch(Exception e){
e.printStackTrace();
}
希望能帮助到你
于 2013-10-24T07:35:02.613 回答
0
你可以这样做:
String absolute = getClass().getProtectionDomain().getCodeSource().getLocation().toExternalForm();
absolute = absolute.substring(0, absolute.length()-1);
absolute = absolute.substring(0, absolute.lastIndexOf("/")+1);
String xmlPath = absolute + "webapp/xml/";
String os = System.getProperty("os.name");
if(os.indexOf("Windows") != -1) {
xmlPath = xmlPath.replace("/", "\\\\");
if(xmlPath.indexOf("file:\\\\") != -1) {
xmlPath = xmlPath.replace("file:\\\\", "");
}
} else if(xmlPath.indexOf("file:") != -1) {
xmlPath = xmlPath.replace("file:", "");
}
File f = new File(xmlPath);
f.mkdir();
于 2013-10-24T08:43:31.933 回答