PDA

View Full Version : [JAVA] split windows e linux


prazision
07-11-2008, 16:58
faccio degli split su stringhe che rappresentano direcotory relative

esempio: j3\txt\44\44-t4231-2.txt

ecco lo split lo eseguo sul backslash

il programma dovrebbe funzionare anche su linux

che devo fare?
splittare sul frontslash?
come faccio a sapere se mi trovo su linux o wind.?
ci sono altri problemi a seconda del sistema per gli split? (ad esempio splitto anche su "-" e su ".")

grazie

british
07-11-2008, 17:13
prova a guardare il metodo statico getProperties() della classe java.lang.System

ciao!

british

prazision
07-11-2008, 17:37
da delle info ma come faccio a sapere se č windows o linux?

garzie

ally
07-11-2008, 17:55
tramite l'uso di System puoi risalire a dati relativi all'os come

separatore :


System.getProperty("file.separator")


o l'os stesso :


System.getProperty("os.name")


ciao Andrea

prazision
07-11-2008, 18:16
tramite l'uso di System puoi risalire a dati relativi all'os come

separatore :


System.getProperty("file.separator")


o l'os stesso :


System.getProperty("os.name")


ciao Andrea

il primo mi č molto utile, grazie

il secondo posso usarlo cosė:
boolean isWindows=System.getProperty("os.name").contains("Windows");

boolean isLinux=System.getProperty("os.name").contains("Linux");

o come?

grazie

ally
07-11-2008, 18:26
entrambi i metodi funzionano...

una classe di test per i valori dati da System.properties :


public class JavaProperties {

public static void main(String[] args) {

Properties props = System.getProperties();
Enumeration enum = props.propertyNames();
for (; enum.hasMoreElements(); ) {
String propName = (String)enum.nextElement();
String propValue = (String)props.get(propName);
System.out.println(propName+" "+propValue);
}

}
}


ciao Andrea

prazision
07-11-2008, 18:34
entrambi i metodi funzionano...


ma intendi quei 2 che ho detto io?

boolean isWindows=System.getProperty("os.name").contains("Windows");

boolean isLinux=System.getProperty("os.name").contains("Linux");


questi insomma?

grazie ancora

prazision
07-11-2008, 18:34
entrambi i metodi funzionano...


ma intendi quei 2 che ho detto io?

boolean isWindows=System.getProperty("os.name").contains("Windows");

boolean isLinux=System.getProperty("os.name").contains("Linux");


questi insomma?

grazie ancora

Hardware Upgrade Forum Database Error
Database Error Database error
The Hardware Upgrade Forum database has encountered a problem.

Please try the following:
  • Load the page again by clicking the Refresh button in your web browser.
  • Open the www.hwupgrade.it home page, then try to open another page.
  • Click the Back button to try another link.
The www.hwupgrade.it forum technical staff have been notified of the error, though you may contact them if the problem persists.
 
We apologise for any inconvenience.