Salut,
A mon avis, tu dois écrire tes fichiers dans le dossier d'installation (donc, sous Windows, dans Program Files), ce qui est protégé pour éviter qu'un programme bidouille un autre programme. Il n'y a pas de droit particulier d'un programme pour écrire dans son propre dossier. Ecrit plutôt tes fichiers dans un dossier créé (qui porte le nom de ton programme) dans le dossier prévu pour ça (sur Windows, AppData/Local).
Sur Windows, tu peux obtenir ce dossier par :
File directory = new File(System.getenv("LOCALAPPDATA"));
Ou, de manière plus générale :
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42
| public class LocalDataUtils {
private final static String OS = System.getProperty("os.name").toLowerCase()
public final static File LOCAL_DATA_DIRECTORY = new File( getLocalDataDirectoryName() );
public static File getLocalDataDirectory(final String directoryName) {
if ( isLinux() ) {
return new File( LOCAL_DATA_DIRECTORY , "." + directoryName);
} else {
return new File( LOCAL_DATA_DIRECTORY , directoryName);
}
}
private static String getLocalDataDirectoryName() {
if ( isWindows() )
return System.getenv("LOCALAPPDATA");
else if ( isMacOSX() )
return System.getProperty("user.home") + "/Library/Application Support";
else if ( isLinux() )
return System.getProperty("user.home");
return System.getProperty("user.dir");
}
public static boolean isWindows() {
return OS.contains("win";
}
public static boolean isMacOSX() {
return OS.contains("mac");
}
public static boolean isLinux() {
return OS.contains("nux");
}
} |
et
File file = new File( LocalDataUtils.getLocalDataDirectory( nomdetonappli ), nomdetonfichier );
Partager