reset password
Author Message
abajpai
Posts: 52
Posted 21:59 Apr 20, 2011 |

Regarding reading from the file, I'm having some trouble with the file path. Previously, I could pass just the file name as a string to the FileReader Object and place the actual file in the working directory of eclipse and it would find the file. However, for some reason this time it's not working unless I specify the absolute path. So my questions is, what am i doing wrong? Or is this how it's supposed to be?

cysun
Posts: 2935
Posted 22:19 Apr 20, 2011 |

The file path thing is a bit tricky with Eclipse because Eclipse doesn't run your project from your project folder - it copies your project to its work directory which is under workspace/.metadata/.plugins/org.eclipse.wst.server.core/.

The easiest thing to do is to use absolute path, but the problem is that you have to change the path when you deploy your code on CS3.

If you don't want to use absolute path, you should place the file under /WebContent of your project folder. This way Eclipse will copy the file together with other files (HTML files, JSP etc.) to the work directory. In your code, you can get the full path to the file by doing the follows:

getServletContext().getRealPath("/" + filename)

Let me know if it works. :)

cysun
Posts: 2935
Posted 22:57 Apr 20, 2011 |

My bad. I just remember that you are doing File I/O in a bean, not a servlet, so you can't do the getServletContext() thing. Just use absolute path then.

Last edited by cysun at 22:58 Apr 20, 2011.
abajpai
Posts: 52
Posted 11:37 Apr 21, 2011 |

That's what I thought as well