Class File, making directories... relative to

Please support our Java advertiser: Programming Forums - DaniWeb Sister Site
Reply

Join Date: Jun 2005
Posts: 28
Reputation: fdrage is an unknown quantity at this point 
Solved Threads: 0
fdrage's Avatar
fdrage fdrage is offline Offline
Light Poster

Class File, making directories... relative to

 
0
  #1
Apr 5th, 2006
Hi,

How do you go about in creating a direcory folder?

I've been playing around with class File which has the method mkDir() (no arguments and returns type boolean), which i thought would be the answer to making a directory but apparently not, or perhaps i just dont understand it.
---
Wasps
Reply With Quote Quick reply to this message  
Join Date: Nov 2004
Posts: 6,143
Reputation: jwenting is just really nice jwenting is just really nice jwenting is just really nice jwenting is just really nice 
Solved Threads: 212
Team Colleague
jwenting's Avatar
jwenting jwenting is offline Offline
duckman

Re: Class File, making directories... relative to

 
0
  #2
Apr 5th, 2006
That's indeed the method you want, but most likely you're not calling it correctly.

Without knowing what you're doing and what's happening as a result it's impossible to say more than that.
As people are clearly allowed to attack me but I'm not allowed to defend myself, I no longer post to this site.
Reply With Quote Quick reply to this message  
Join Date: Jun 2005
Posts: 28
Reputation: fdrage is an unknown quantity at this point 
Solved Threads: 0
fdrage's Avatar
fdrage fdrage is offline Offline
Light Poster

Re: Class File, making directories... relative to

 
0
  #3
Apr 5th, 2006
OK this works, i forgot to add the "\\" at the end of the file argument

  1. import java.io.File;
  2. public class testFile {
  3. public static void main(String[] args) {
  4. File file = new File("C:\\tmpFolder\\");
  5. System.out.println(file.mkdir()? "success" :"failed");
  6. }
  7. }

also worked out that if you want a relative path i just need to remove the "C:" so it would be like this \\tmpfolder\\ :cheesy:
---
Wasps
Reply With Quote Quick reply to this message  
Join Date: Nov 2004
Posts: 6,143
Reputation: jwenting is just really nice jwenting is just really nice jwenting is just really nice jwenting is just really nice 
Solved Threads: 212
Team Colleague
jwenting's Avatar
jwenting jwenting is offline Offline
duckman

Re: Class File, making directories... relative to

 
0
  #4
Apr 6th, 2006
That's correct. And if you want to create a complete directory path even if parts don't exist, use mkDirs.

Some advise though: don't hardcode path separators. Use the system property "path.separator" instead to make your code platform independent (and of course always use relative paths to some system property).
As people are clearly allowed to attack me but I'm not allowed to defend myself, I no longer post to this site.
Reply With Quote Quick reply to this message  
Join Date: Jun 2005
Posts: 28
Reputation: fdrage is an unknown quantity at this point 
Solved Threads: 0
fdrage's Avatar
fdrage fdrage is offline Offline
Light Poster

Re: Class File, making directories... relative to

 
0
  #5
Apr 7th, 2006
And if you want to create a complete directory path even if parts don't exist, use mkDirs.
what do you mean by "even if parts don't exist" , can u give us some example, thx
---
Wasps
Reply With Quote Quick reply to this message  
Join Date: Nov 2004
Posts: 6,143
Reputation: jwenting is just really nice jwenting is just really nice jwenting is just really nice jwenting is just really nice 
Solved Threads: 212
Team Colleague
jwenting's Avatar
jwenting jwenting is offline Offline
duckman

Re: Class File, making directories... relative to

 
0
  #6
Apr 7th, 2006
mkDirs will create the entire path you pass it, including non-existent directories.
So if you pass it "/usr/myapp/data/20060407/xml" and only /usr/myapp" exists, it will first create data, then 20060407 under that, and finally xml under that to complete the structure.
mkDir would just give you an error.
As people are clearly allowed to attack me but I'm not allowed to defend myself, I no longer post to this site.
Reply With Quote Quick reply to this message  
Reply

This thread is more than three months old.
Perhaps start a new thread instead?
Message:


Thread Tools Search this Thread



About Us | Contact Us | Advertise | DaniWeb | Acceptable Use Policy | RSS Feed

©2003 - 2009 DaniWeb® LLC