Jump to content

Set the java cache directory

- - - - -

  • Please log in to reply
4 replies to this topic

#1
dunnkers

dunnkers

    Learning Programmer

  • Members
  • PipPipPip
  • 31 posts
Hello,

I want to set the cache directory because i cannot use AppData/Local/Temp/ for a certain reason. I'm using URLClassLoader, and i want it to temporarily save in another folder instead of AppData/Local/Temp/. How can i do this?

Please help,
Thanks Dunnkers.

#2
ZekeDragon

ZekeDragon

    Writes binary right handed and hex left handed

  • Moderators
  • 2,103 posts
You need to change the Java Runtime's tmpdir property. You can do that like so:
java -Djava.io.tmpdir=C:\my\file\location MyProgram
See if that works, since I believe URLClassLoader just saves temp data to the folder on that property.
Wow I changed my sig!

#3
dunnkers

dunnkers

    Learning Programmer

  • Members
  • PipPipPip
  • 31 posts
How can i change this when in java? In my code itself? Also, i cannot use exec.

#4
ZekeDragon

ZekeDragon

    Writes binary right handed and hex left handed

  • Moderators
  • 2,103 posts
I haven't tested it, but I'd use System.setProperty:
String propertyName = "java.io.tmpdir";

String oldLocation = System.getProperty(propertyName);

System.setProperty(propertyName, "/location/of/file");


// Do your other stuff here.


System.setProperty(propertyName, oldLocation);

Wow I changed my sig!

#5
dunnkers

dunnkers

    Learning Programmer

  • Members
  • PipPipPip
  • 31 posts
Thanks allot! This worked for me!




1 user(s) are reading this topic

0 members, 1 guests, 0 anonymous users