“”在jsp(tomcat)中采用system32路径而不是当前路径

时间:2013-08-03 10:33:59

标签: jsp relative-path

以下是我用于在存在此jsp文件的同一文件夹中创建文本文件的代码。

<%@ page import="java.io.*"%>
<% String nameOfTextFile = "./test.txt";
File file=new File(nameOfTextFile);
boolean exists = file.exists();
if(exists)
    {
    out.println("file exist");
    }
else
    {
    file.createNewFile();
    out.println("file created");
    }
%>

此jsp文件保存在tomcat / webapps / practice /文件夹中。

我的问题是当我使用这个“./text.txt”作为文件路径时,它被视为windows / system32 / path(当tomcat以admin身份运行时)和tomcat / bin / path(如果tomcat不是以管理员身份运行。)

在1个月之前,我使用相同的代码创建文本文件是相同的文件夹,它工作正常,那时我赢得了7作为我的操作系统,但现在我赢了8.我不确定这个问题是因为操作系统或其他一些事情。

任何人都可以帮忙......?

0 个答案:

没有答案
相关问题