Want to protect your cyber security and still get fast solutions? Ask a secure question today.Go Premium

x
  • Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 814
  • Last Modified:

getTempDir() method

Hi all,
Is there anyone that could give me a good website where to find the getTempDir() method with its class easy to download?
This method is supposed to get the local temporary directory. I couldn't find it in the Java SDK 1.4
but looking for it on the web, i found that some people already created some class with such a method included in. For example there is a class called org.apache.commons.httpclient.methods.GetMethod that has the getTempDir() method. Unfortunately, i couldn't find any good spot where to download such a class...
Thanks in advance for you help!!
0
Baha
Asked:
Baha
  • 6
  • 4
  • 2
  • +4
1 Solution
 
CEHJCommented:
String tempDir = System.getProperty("java.io.tmpdir");
0
 
knightEknightCommented:
and where can we get a list of valid system properties to pass to that method?
0
 
CEHJCommented:
Do you mean how can you find out what system properties are available? If so, run this class without parameters:

public class Props {

  public static void main(String[] args){
    if(args.length > 0){
     for(int i = 0;i < args.length;i++){
      System.out.println(System.getProperty(args[0]));
     }
    }
    else {
      System.getProperties().list(System.out);
    }
  }
}
0
Independent Software Vendors: We Want Your Opinion

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

 
knightEknightCommented:
thanks!
0
 
Venci75Commented:
If you need to create a temporary file, use:
java.io.File.createTempFile();

To get the sytem properties list, I use:
System.getProperties().store(System.out, "");
0
 
TimYatesCommented:
> System.getProperties().store(System.out, "");

Nice!!! :-D
0
 
CEHJCommented:
>>
To get the sytem properties list, I use:
System.getProperties().store(System.out, "");
>>

Why?
0
 
Venci75Commented:
.... that is because I didn't see in your comment that you are doing the same using the list() method :))
0
 
CEHJCommented:
You should call list, otherwise you're creating Writers quite redundantly.
0
 
Venci75Commented:
actually - this:
System.getProperties().store(System.out, "");
can be used only for test purposes
0
 
BahaAuthor Commented:
HI thx for replying to my question!
Actually, i need such a method for being able to get the local temporary directory on any computer using windows.
I use a function that attaches a file that is stored in the first parameter (the path). Here is the function:
attachFile("K:\Project\Report.xml", "file", "Report.xml","multipart/form-data");
So instead of writing this current path, i'd like to use the getTempDir method or the getProperties one in order to get the file which has been stored before in the temporary directory. Maybe if i put as the first parameter :
attachFile(System.getProperties().store(System.out, "Report.xml"), "file", "Report.xml","multipart/form-data");
Maybe this could work? but i don't think so.. well i hope you understood my question. Thx in advance.
0
 
TimYatesCommented:
As CEHJ said in his first post...

String tempDir = System.getProperty("java.io.tmpdir");
0
 
CEHJCommented:
No, with this code

>>
attachFile(System.getProperties().store(System.out, "Report.xml"), "file", "Report.xml","multipart/form-data");
>>

even if System.getProperties().store were appropriate here (it isn't) it's not good code anyway, for the reasons i've already given.

With your function, it should be
attachFile(System.getProperty("java.io.tmpdir"), "file", "Report.xml","multipart/form-data");

0
 
Venci75Commented:
to CEHJ:
this is the code of the list method:
    public void list(PrintWriter out) {
     out.println("-- listing properties --");
     Hashtable h = new Hashtable();
     enumerate(h);
     for (Enumeration e = h.keys() ; e.hasMoreElements() ;) {
         String key = (String)e.nextElement();
         String val = (String)h.get(key);
         if (val.length() > 40) {
          val = val.substring(0, 37) + "...";
         }
         out.println(key + "=" + val);
     }
    }

as you can see - you will have a problem when a value length exceeds 40 characters.
Also list() method is not appropriate for strings that contain '=', '\n' etc.
0
 
CEHJCommented:
>>as you can see - you will have a problem when a value length exceeds 40 characters

Yes, i'm aware of that. The code i posted is not intended to be used in a critical context, as should be clear, since the properties are being dumped to stdout. If any property is truncated, it can be inspected properly by passing the property in question as a parameter to the program.
0
 
CleanupPingCommented:
Baha:
This old question needs to be finalized -- accept an answer, split points, or get a refund.  For information on your options, please click here-> http:/help/closing.jsp#1 
EXPERTS:
Post your closing recommendations!  No comment means you don't care.
0
 
jimmackCommented:
No comment has been added lately, so it's time to clean up this TA.
I will leave a recommendation in the Cleanup topic area that this question is:

Accept CEHJ's comment as answer.

Please leave any comments here within the next seven days.

PLEASE DO NOT ACCEPT THIS COMMENT AS AN ANSWER!

jimmack
EE Cleanup Volunteer
0

Featured Post

Get your problem seen by more experts

Be seen. Boost your question’s priority for more expert views and faster solutions

  • 6
  • 4
  • 2
  • +4
Tackle projects and never again get stuck behind a technical roadblock.
Join Now