01: /**
02: * @creation 28/02/05
03: */package com.memoire.vainstall;
04:
05: import java.io.File;
06: import java.io.IOException;
07: import java.net.URI;
08:
09: /**
10: * Extension of java.io.File that overcomes a problem in File.canWrite
11: * on Windows XP. Breifly, new File("C:\\Program Files").canWrite()
12: * always returns false on Win XP even if the directory is writable.
13: * This class overrides canWrite. The new method is used
14: * only if the platform is Windows and the file is a directory.
15: * Otherwise, the parental method is used.
16: * @author Dick Repasky
17: */
18:
19: public class VAFile extends File {
20:
21: public VAFile(File parent, String child) {
22: super (parent, child);
23: }
24:
25: public VAFile(String pathname) {
26: super (pathname);
27: }
28:
29: public VAFile(String parent, String child) {
30: super (parent, child);
31: }
32:
33: public VAFile(URI uri) {
34: super (uri);
35: }
36:
37: public VAFile(File file) {
38: super (file.getAbsolutePath());
39: }
40:
41: public boolean canWrite() {
42: boolean answer = super .canWrite();
43: if (!answer && Setup.IS_WIN && isDirectory()) {
44: answer = canWriteDirectory();
45: }
46: return answer;
47: }
48:
49: public File getParentFile() {
50: return new VAFile(super .getParentFile());
51: }
52:
53: private boolean canWriteDirectory() {
54: boolean answer = false;
55: File f = null;
56: try {
57: f = createTempFile("idw", "tmp", this );
58: answer = true;
59: } catch (IOException ioe) {
60: } // do nothing
61: finally {
62: if (f != null)
63: f.delete();
64: }
65: return answer;
66: }
67: }
|