Reputation: 3081
Dear community members,
I have a small problem with the following code. I think it should open the explorer in the C:\Users\Me\AppData\Local\Temp\ directory. However that does not work, actually nothing happens. No errors.
I have used the following code:
import java.awt.Desktop;
import java.io.File;
import java.io.IOException;
public class Main {
public static void main(String[] args) {
try {
Desktop.getDesktop().open(File.createTempFile("abcd", ".temp").getParentFile());
} catch (IOException e) {
e.printStackTrace();
}
}
}
If I replace it with a normal file, like new File("C:\"), then it does work. Can someone explain to me why it does not work?
PS: guys I forgot to tell you I also tried it with some characters like "abcd", it still gives nothing and shows nothing!
Upvotes: 1
Views: 5930
Reputation: 1035
Just use new File(System.getProperty("java.io.tmpdir"))
: that's the temp directory. No need for dirty tricks with the parent of a useless temporary file...
Upvotes: 5
Reputation: 10020
According to the docs for File.createTempFile()
, if the prefix (first argument) contains fewer than three characters, an IllegalArgumentException
will be thrown. You should see it in your console output.
Upvotes: 0