【发布时间】:2014-06-25 06:06:15
【问题描述】:
我正在尝试制作一个在特定文件夹中创建文件的 webapps。这个应用程序应该可以在 windows 和 ubuntu 上运行,但是它们有不同的文件结构。那么如何在创建文件时提及路径,在 Ubuntu 中我也需要使用权限。如何授予我尝试在其中创建文件的文件夹的权限。我为此使用 java,这是我的代码:
//bfr=new BufferedReader(new InputStreamReader(System.in));
String fileName="/home/hemant/"+credentials[3];
String content=String.valueOf(n)+"\n"+messages.length;
File file=new File(fileName);
if(!file.exists()){
System.out.println("filecreated");
file.createNewFile();
}
我的应用是一个基于 tomcat 的应用。我该怎么办?我是新手,不知道。
【问题讨论】:
-
尝试使用属性文件,或者在紧要关头使用
System.getProperty("os.name");。 -
假设您要在服务器端保存文件,那么这个问题基本上是 stackoverflow.com/a/2663855/3651800 的重复项(尽管该答案基本上说“不要这样做”)
标签: java tomcat web-applications