-----BEGIN PGP SIGNED MESSAGE----- Hash: SHA1 On 1/28/2015 11:48 AM, David kerber wrote: > On 1/28/2015 2:03 PM, Hyder Hashmi wrote: >> Hi, >> >> I am working on a small project and need your help in this. >> >> I have a java program in which I read and write in a file that is >> located in the current folder. >> >> Now I have written a few servlets and trying to use the previous >> code along with servlets. >> >> Tomcat is searching for the file in its bin folder and giving >> FileNotFoundException. > > To Tomcat, the /bin folder is it's current directory. > >> >> If I use my java code without the servlet it is checking for the >> file in current folder (which is my requirment). > > It looks like you need to refactor your code to allow you to > specify where to find the file when you call the method that does > the work. Then the servlet and your pure java code can both > specify as needed. Of course, a servlet may not have permissions > to anything outside of its own hierarchy, but that's a separate > issue. > > >> >> I want to ensure that when I use my java code along with >> servlets, it should read and write in the file from current >> folder(Project folder in tomcat's webapps). >> >> I am not using any IDE, the code is written in Notepad and being >> executed from CommandLine. >> >> I have spent long time on Internet to find the resolution but in >> vain. >> >> Request to help me with this situation . >> >> Hoping for a positive reply. >> >> Thanks for in advance for all the help. >> >> Regards, Hyder.
Hyder, In general, this is pretty unpleasant to do which is why you're having a tough time finding out how to do it. 1. What happens if the WAR file is not exploded? 2. What happens if Tomcat does not have write access to where the web application is deployed? - -- many other unpleasant questions -- If you must do this, read the javadoc for ServletContext, in particular the getRealPath method. . . . just my two cents /mde/ -----BEGIN PGP SIGNATURE----- Version: GnuPG v2 iQEcBAEBAgAGBQJUyUFzAAoJEEFGbsYNeTwt1Q8H/RINjaxS6a/jIuhbleGIjTW0 hMlGwnWayzcSxVjWwdZoEc5mIvyReIMrt4j+d6vRrSCp8+Dae6hHSZGL7h8rCCDE slsmolNruiMP3EMmJLE5fsxginUczZwcRLihjjIrYhlZcsSmVEZEX/MFaBuT+zCO wjftBs0rkZ/h+5g1sl79YC5SiCT2zAA3T1YTzIzajGMEtBNixTd131WC0beRuPQh UgIYAjQwXOfqu9f+SU96Bh5V2avhzQ06J+K7HI9TgckIGymxL7NCeTkTx1fpR0bd 9lWik6RIPDV0UT76eXIF1I8d/8qu7kHMt43LnLuUflTeRO8qxZYXP2H/p2onDRc= =78++ -----END PGP SIGNATURE----- --- This email is free from viruses and malware because avast! Antivirus protection is active. http://www.avast.com --------------------------------------------------------------------- To unsubscribe, e-mail: users-unsubscr...@tomcat.apache.org For additional commands, e-mail: users-h...@tomcat.apache.org