controlleur
Messages postés65Date d'inscriptionmercredi 27 janvier 2010StatutMembreDernière intervention16 avril 2013
-
21 mars 2012 à 16:37
controlleur
Messages postés65Date d'inscriptionmercredi 27 janvier 2010StatutMembreDernière intervention16 avril 2013
-
21 mars 2012 à 17:38
Bonjour
j'ai fait un programme java sous Linux ( Eclipse),il compile bien , et je veux le tester sur Windows.
est ce qu'il y a un moyen pour tester dans le main sur quel OS le programme il tourne :
comme ça s'il est sous linux il peut utiliser des commandes linux
ou sous Windows : il utilise des commandes Dos
controlleur
Messages postés65Date d'inscriptionmercredi 27 janvier 2010StatutMembreDernière intervention16 avril 2013 21 mars 2012 à 17:38
it's ok :) j'ai trouver ..Merci MR.google
public class OSValidator {
public static void main(String[] args) {
if (isWindows()) {
System.out.println("This is Windows");
} else if (isMac()) {
System.out.println("This is Mac");
} else if (isUnix()) {
System.out.println("This is Unix or Linux");
} else if (isSolaris()) {
System.out.println("This is Solaris");
} else {
System.out.println("Your OS is not support!!");
}
}
public static boolean isWindows() {
String os = System.getProperty("os.name").toLowerCase();
// windows
return (os.indexOf("win") >= 0);
}
public static boolean isMac() {
String os = System.getProperty("os.name").toLowerCase();
// Mac
return (os.indexOf("mac") >= 0);
}
public static boolean isUnix() {
String os = System.getProperty("os.name").toLowerCase();
// linux or unix
return (os.indexOf("nix") >= 0 || os.indexOf("nux") >= 0);
}
public static boolean isSolaris() {
String os = System.getProperty("os.name").toLowerCase();
// Solaris
return (os.indexOf("sunos") >= 0);