reset password
Author Message
cbort
Posts: 95
Posted 23:18 May 03, 2011 |

Where do I put the text file so that it can be read by the program on the server and what path should I use to access it?

dely
Posts: 32
Posted 00:42 May 04, 2011 |

Why are you trying to read a text file?  Anyways, to find the path, just have your servlet create a new file and print the pathname for it.  Then using that, you can create an absolute path to your file.

cbort
Posts: 95
Posted 07:01 May 04, 2011 |

I assume it will be required for the midterm and I would like to not lose points on it this time;)

for any one that doesn't already know you can put the text file in WEB-INF and use:

String filePath = getServletContext().getRealPath("WEB-INF/file.txt");

 

Good luck on the midterm everyone 

cysun
Posts: 2935
Posted 07:43 May 04, 2011 |
cbort wrote:

...

String filePath = getServletContext().getRealPath("WEB-INF/file.txt");

...

It should be

String filePath = getServletContext().getRealPath("/WEB-INF/file.txt");

And if you want to use absolute path, place the file under the home directory of your account and use the path /home/<username>/<filename>, e.g. /home/cs320stu31/file.txt.