I'm confused - is this on a Windows or a Solaris system? A "D:" file designation indicates Windows, a "/" file separator indicates Solaris.
More importantly, "new File(...)" creates a File object, not a file. Unless the file existed before you will always get false from isFile() and exists(). If you want to create a new empty file, call createNewFile().
This code is present in a jsp file. The Weblogic is running on Sun Solaris system.
I open the web application from a Windows system and thus the Windows File path.
I need to confirm whether a File exists at a given FilePath in windows.
So I use the Windows File Path, try creating a File object, if file exists at the FilePath then file1.isFile() should return true.
Hope this provides more clarity.
Well this is the scenario, the user needs to upload a file. In an earlier page, the file path is already collected.
Now before uploading to server, if the given filepath is valid, upload should happen or else browse option needs to be enabled for the user
to upload another file.
I did not know about JSP restrictions to access file systems. Seems quite logical now. Thanks to Tim to point that one out.
That was why I was trying to check if file is valid by creating a File object out of the filepath and validating it (either using exists() or isFile()).
First suggestion: get rid of that requirement. It's nonsense anyway. The way to allow a user to upload a file has already been posted in this thread. It isn't the responsibility of the server to manage the process whereby the user chooses what file to upload, nor is it even possible for the server to do that.
It's also impossible for the user to upload a file which doesn't exist. The browser takes care of that.