?
Solved

getTempDir() method

Posted on 2003-03-17
18
Medium Priority
?
809 Views
Last Modified: 2008-03-03
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
Comment
Question by:Baha
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 6
  • 4
  • 2
  • +4
18 Comments
 
LVL 86

Accepted Solution

by:
CEHJ earned 320 total points
ID: 8153213
String tempDir = System.getProperty("java.io.tmpdir");
0
 
LVL 33

Expert Comment

by:knightEknight
ID: 8155510
and where can we get a list of valid system properties to pass to that method?
0
 
LVL 86

Expert Comment

by:CEHJ
ID: 8155556
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
Optimize your web performance

What's in the eBook?
- Full list of reasons for poor performance
- Ultimate measures to speed things up
- Primary web monitoring types
- KPIs you should be monitoring in order to increase your ROI

 
LVL 33

Expert Comment

by:knightEknight
ID: 8155835
thanks!
0
 
LVL 9

Expert Comment

by:Venci75
ID: 8158055
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
 
LVL 35

Expert Comment

by:TimYates
ID: 8158822
> System.getProperties().store(System.out, "");

Nice!!! :-D
0
 
LVL 86

Expert Comment

by:CEHJ
ID: 8158872
>>
To get the sytem properties list, I use:
System.getProperties().store(System.out, "");
>>

Why?
0
 
LVL 9

Expert Comment

by:Venci75
ID: 8158928
.... that is because I didn't see in your comment that you are doing the same using the list() method :))
0
 
LVL 86

Expert Comment

by:CEHJ
ID: 8158949
You should call list, otherwise you're creating Writers quite redundantly.
0
 
LVL 9

Expert Comment

by:Venci75
ID: 8158981
actually - this:
System.getProperties().store(System.out, "");
can be used only for test purposes
0
 

Author Comment

by:Baha
ID: 8159153
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
 
LVL 35

Expert Comment

by:TimYates
ID: 8159272
As CEHJ said in his first post...

String tempDir = System.getProperty("java.io.tmpdir");
0
 
LVL 86

Expert Comment

by:CEHJ
ID: 8173219
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
 
LVL 9

Expert Comment

by:Venci75
ID: 8173255
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
 
LVL 86

Expert Comment

by:CEHJ
ID: 8173392
>>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
 

Expert Comment

by:CleanupPing
ID: 9058637
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
 
LVL 15

Expert Comment

by:jimmack
ID: 9726919
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

Free Tool: Site Down Detector

Helpful to verify reports of your own downtime, or to double check a downed website you are trying to access.

One of a set of tools we are providing to everyone as a way of saying thank you for being a part of the community.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Java had always been an easily readable and understandable language.  Some relatively recent changes in the language seem to be changing this pretty fast, and anyone that had not seen any Java code for the last 5 years will possibly have issues unde…
Introduction This article is the first of three articles that explain why and how the Experts Exchange QA Team does test automation for our web site. This article explains our test automation goals. Then rationale is given for the tools we use to a…
Viewers learn about the third conditional statement “else if” and use it in an example program. Then additional information about conditional statements is provided, covering the topic thoroughly. Viewers learn about the third conditional statement …
This theoretical tutorial explains exceptions, reasons for exceptions, different categories of exception and exception hierarchy.
Suggested Courses
Course of the Month12 days, 15 hours left to enroll

777 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question