On Mon, 2015-02-09 at 09:58 +0530, Hyder Hashmi wrote:
> Hi All,
> 
> When I execute the following code in my project folder, it creates the file
> in my current folder(project folder).
> 
> import java.io.File;
> public class CreateFile{
>       File f = null;
>       try{
>          f = new File("test.txt");
>          bool = f.createNewFile();
>          System.out.println("File created: "+bool);
>          }catch(Exception e){
>          e.printStackTrace();
>       }
> }
> 
First, there's no way that compiles.  Perhaps that block is supposed to
be wrapped in a method?

> I am now calling this class in my servlet.
> The servlet is executing perfectly on the tomcat, however, the file is
> getting created in the tomcat's bin folder instead of my project folder
> placed in the webapps.
> 
> If I specify the path, then it creates the file on that location , however,
> that will be hardcoding and will not work on the other computer.
> 

Second, you asked this question last week and you got several replies
offering guidance.  What advice, if any, did you follow and how did it
turn out?  (Hint: it's annoying when people take time to help and you
don't listen to them but want more help.)

As one of the replies suggested, probably the best approach is to set an
absolute path in either a system or context property.  Then obtain that
value during servlet init and pass it to the CreateFile class somehow
(via a constructor or a set method, or as a param to the create method
etc.).

--- Tim

> Please help.
> Thanks in advance
> Hyder!



---------------------------------------------------------------------
To unsubscribe, e-mail: users-unsubscr...@tomcat.apache.org
For additional commands, e-mail: users-h...@tomcat.apache.org

Reply via email to