|
|
|
![]() |
|
Strumenti |
![]() |
#1 |
Senior Member
Iscritto dal: May 2005
Città: Roma
Messaggi: 7938
|
[JAVA] Runtime.getRuntime().exec(comandi) e percorsi remoti
sto eseguendo dei file dal mio programma seguendo questa sintassi:
Codice:
String[] comandi = {"cmd", "/C", file.getAbsolutePath()}; Runtime.getRuntime().exec(comandi);
__________________
My gaming placement |
![]() |
![]() |
![]() |
#2 |
Senior Member
Iscritto dal: May 2005
Città: Roma
Messaggi: 7938
|
stessa cosa se metto
Codice:
Desktop.getDesktop().open(file);
__________________
My gaming placement |
![]() |
![]() |
![]() |
#3 |
Senior Member
Iscritto dal: May 2005
Città: Roma
Messaggi: 7938
|
credo di aver risolto, spulciando in rete ho trovato questi frammenti di codice, che al mmomento sembrano funzionare
Codice:
// generate uri according to the filePath private URI getFileURI(String filePath) { URI uri = null; filePath = filePath.trim(); if (filePath.indexOf("http") == 0 || filePath.indexOf("\\") == 0) { if (filePath.indexOf("\\") == 0) { filePath = "file:" + filePath; filePath = filePath.replaceAll("#", "%23"); } try { filePath = filePath.replaceAll(" ", "%20"); URL url = new URL(filePath); uri = url.toURI(); } catch (MalformedURLException ex) { ex.printStackTrace(); } catch (URISyntaxException ex) { ex.printStackTrace(); } } else { File file = new File(filePath); uri = file.toURI(); } return uri; } public void launchFile(File file) { if (!Desktop.isDesktopSupported()) { return; } Desktop dt = Desktop.getDesktop(); try { dt.open(file); } catch (IOException ex) { // this is sometimes necessary with files on other servers ie // \xxxxxx.xls launchFile(file.getPath()); } } // this can launch both local and remote files public void launchFile(String filePath) { if (filePath == null || filePath.trim().length() == 0) { return; } if (!Desktop.isDesktopSupported()) { return; } Desktop dt = Desktop.getDesktop(); try { dt.browse(getFileURI(filePath)); } catch (Exception ex) { ex.printStackTrace(); } } }
__________________
My gaming placement |
![]() |
![]() |
![]() |
Strumenti | |
|
|
Tutti gli orari sono GMT +1. Ora sono le: 03:11.