The moose likes Java in General and the fly likes Writing a file to unix directory Big Moose Saloon
  Search | Java FAQ | Recent Topics
Register / Login
JavaRanch » Java Forums » Java » Java in General
Reply Bookmark "Writing a file to unix directory" Watch "Writing a file to unix directory" New topic
Author

Writing a file to unix directory

Tony May
Greenhorn

Joined: Jan 04, 2002
Posts: 17
I have a web application which uploads a file from the client and stores them in a directory. This works fine in windows, but on a unix server
does not work. I am not getting a stack trace and
have changed the directory path slashes from \ to / but alas nothing. I am using Apache Tomcat 4.1 server.
Any help would be appreciated
Tony
Peter den Haan
author
Ranch Hand

Joined: Apr 20, 2000
Posts: 3252
So what is the stack trace?
- Peter
Tony May
Greenhorn

Joined: Jan 04, 2002
Posts: 17
Apologies, here it is -
I am creating the file object like the following
File file = new File ("../webapps/NAMEOFWAR", "fileName");
and getting the following error
java.io.IOException: No such file or directory
at java.io.UnixFileSystem.createFileExclusively(Native Method)
at java.io.File.createNewFile(File.java:688)
at com.vetsWest.upload.UploadHelper.uploadFile(UploadHelper.java:36)
at com.vetsWest.upload.UploadAction.perform(UploadAction.java:122)
at org.apache.struts.action.ActionServlet.processActionPerform(ActionServlet.java:1786)
at com.vetsWest.VetsWestServlet.processActionPerform(VetsWestServlet.java:134)
at org.apache.struts.action.ActionServlet.process(ActionServlet.java:1585)
at org.apache.struts.action.ActionServlet.doPost(ActionServlet.java:509)
at javax.servlet.http.HttpServlet.service(HttpServlet.java:760)
at javax.servlet.http.HttpServlet.service(HttpServlet.java:853)
Peter den Haan
author
Ranch Hand

Joined: Apr 20, 2000
Posts: 3252
Could it simply be that the current working directory is not quite what you expect it to be? What you're trying to do looks distinctly suspect and non-portable to me. AFAIK you don't get any guarantees that the web-app root or anything else is the current working directory. And as the Tomcat startup scripts under Windows and Unix are different and started in different ways, they could easily explain why the working directory is different.
A few general hints. ServletContext.getRealPath() gives the filesystem path for any web-app resource; you can perhaps navigate relative to a known resource. ServletContext.getResource() retrieves a resource URL relative to the web-app root. ServletContext.getResourceAsStream() opens an InputStream on a resource.
Beware that some application servers run your web-app straight out of the war or even out of a database. For truly portable applications, you cannot rely on getRealPath().
- Peter
 
 
subject: Writing a file to unix directory
 
Threads others viewed
displaying file in jsp
move files from one machine to another
Create a file at runtime
Prevent uploading executables
saving xml file to a different server/dir in a servlet
WebSphere development made easy
without the weight of IBM tools
http://www.myeclipseide.com

cast iron skillet 49er

more from paul wheaton's glorious empire of web junk: cast iron skillet diatomaceous earth rocket mass heater sepp holzer raised garden beds raising chickens lawn care CFL flea control missoula heat permaculture