New File in Current Directory (jsp + tomcat)

T

tiewknvc9

Hi!

I created a single jsp page that is just supposed to create a new jsp
file in the current directory. I put together this code (see below),
this code will always put the file in the "bin" directory...
Disallowing me to access it again with my application.

I would like it to create the file in the Same directory as the jsp
page... but I dont know how.

If you copy and paste this into a jsp page, and run it... you should
see my problem in action.

Thanks in advance!

<%@page import="java.io.*"%>
<%
String curDir = System.getProperty("user.dir");

File filFile = new File(curDir + "\\pleaseWork.txt");
boolean success = filFile.createNewFile();
if (success){
out.print("created new file" + curDir + "\\pleaseWork.txt");
}else{
out.print("updated file" + curDir + "\\pleaseWork.txt");
}
%>
 
?

=?ISO-8859-1?Q?Arne_Vajh=F8j?=

tiewknvc9 said:
I created a single jsp page that is just supposed to create a new jsp
file in the current directory.
I would like it to create the file in the Same directory as the jsp
page... but I dont know how.

1) I think you are looking for application.getRealPath("/pleaseWork.txt")

2) I think you should drop the approach - it is not good.

Arne
 
T

tiewknvc9

why do you think I should drop the approach?
1) I think you are looking for application.getRealPath("/pleaseWork.txt")

2) I think you should drop the approach - it is not good.

Arne
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

Forum statistics

Threads
473,773
Messages
2,569,594
Members
45,120
Latest member
ShelaWalli
Top