This week's book giveaway is in the Servlets forum.
We're giving away four copies of Murach's Java Servlets and JSP and have Joel Murach on-line!
See this thread for details.
The moose likes Beginning Java and the fly likes creating directory name for file upload Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login


Win a copy of Murach's Java Servlets and JSP this week in the Servlets forum!
JavaRanch » Java Forums » Java » Beginning Java
Bookmark "creating directory name for file upload" Watch "creating directory name for file upload" New topic
Author

creating directory name for file upload

elicia dent
Greenhorn

Joined: Jul 13, 2009
Posts: 9
Hello All
Please , what is the syntax to create a filename that includes a variable, i.e.,

var orgName = "Staples";
String fileDir = "/tmp" + orgName;
File saveTo = new File(fDir, fileName);

Obviously, the first line doesn't work, but I can't figure out how to do it for some reason.

Many thanks
Elicia
Zandis Murāns
Ranch Hand

Joined: Aug 18, 2009
Posts: 174



In all cases you should better user System.getProperty("java.io.tmpdir") instead of static temp directory names and File.separator instead of directory separator chars (slashes and backslashes).

File saveTo = new File(fDir, fileName); This will create file (directory) object, but not real directory on your hard drive. Use saveTo.mkdirs() to actually create directory.
elicia dent
Greenhorn

Joined: Jul 13, 2009
Posts: 9
Thank you.
 
Consider Paul's rocket mass heater.
 
subject: creating directory name for file upload
 
Similar Threads
Check the file/found or not
java io
Redirect after file upload
Help with java input file
String to InputStream for XSL transformation