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 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89
|
/**
*
* @return le fichier de propriétés du fichier de l'application
*/
public static File getAppropertiesFile() {
String osName = System.getProperty("os.name");
File appPropertiesFile = new File("appProperties");
String userHome = System.getProperty("user.home");
if (osName.equals("Mac OS X")) {
// Si le systeme d'exploitation est Mac Os X
// On enregistre le fichier appProperties dans
// $HOME/Library/Application Support/Nom du logiciel/
try {
File library = new File(userHome, "Library");
File applicationSupport = new File(library,
"Application Support");
File appPropertiesFolder = new java.io.File(applicationSupport,
Variables.APP_NAME);
if (!appPropertiesFolder.isDirectory()) {
// cree le repertoire si il n'existe pas
if (appPropertiesFolder.mkdir()) {
}
}
appPropertiesFile = new File(appPropertiesFolder,
"appProperties");
appPropertiesFile.createNewFile();
} catch (IOException ex) {
Logger.getLogger("global").log(Level.SEVERE, null, ex);
}
} else if (osName.equals("Linux")) {
// Si le systeme d'exploitation est Linux
// On enregistre le fichier appProperties dans $HOME/.Nom du
// logiciel/
try {
File appPropertiesFolder = new java.io.File(userHome, "."
+ Variables.APP_NAME);
if (!appPropertiesFolder.isDirectory()) {
// cree le repertoire si il n'existe pas
if (appPropertiesFolder.mkdir()) {
}
}
appPropertiesFile = new File(appPropertiesFolder,
"appProperties");
appPropertiesFile.createNewFile();
} catch (IOException ex) {
Logger.getLogger("global").log(Level.SEVERE, null, ex);
}
} else if (osName.equals("Windows XP")) {
// Si le systeme d'exploitation est Windows XP
// On enregistre le fichier appProperties dans $HOME/Application
// Data/Nom du logiciel
try {
File applicationData = new File(userHome, "Application Data");
File appPropertiesFolder = new java.io.File(applicationData,
Variables.APP_NAME);
if (!appPropertiesFolder.isDirectory()) {
// cree le repertoire si il n'existe pas
if (appPropertiesFolder.mkdir()) {
}
}
appPropertiesFile = new File(appPropertiesFolder,
"appProperties");
appPropertiesFile.createNewFile();
} catch (IOException ex) {
Logger.getLogger("global").log(Level.SEVERE, null, ex);
}
} else if (osName.equals("Windows Vista")) {
// Si le systeme d'exploitation est Windows Vista
// On enregistre le fichier appProperties dans
// $HOME/AppData/Roaming/Nom du logiciel
File appData = new File(userHome, "AppData");
File roaming = new File(appData, "Roaming");
File appPropertiesFolder = new File(roaming, Variables.APP_NAME);
if (!appPropertiesFolder.isDirectory()) {
// cree le repertoire si il n'existe pas
if (appPropertiesFolder.mkdir()) {
}
}
appPropertiesFile = new File(appPropertiesFolder, "appProperties");
try {
appPropertiesFile.createNewFile();
} catch (IOException ex) {
ex.printStackTrace();
}
}
return appPropertiesFile;
} |
Partager