JProgressBar, rafraichissement en fonction d'une tache a duree inderterminee
codessources_Cain
Messages postés8Date d'inscriptiondimanche 14 mars 2004StatutMembreDernière intervention23 juillet 2009
-
21 avril 2004 à 06:28
codessources_Cain
Messages postés8Date d'inscriptiondimanche 14 mars 2004StatutMembreDernière intervention23 juillet 2009
-
29 avril 2004 à 03:08
Bonjour,
comment faire en sorte que la progression d'une tâche soit fidelement affichee alors que la durée de celle-ci peut fortement varier ?
exemple de tâche : scan de disque dur ou de cd-ROM ( en terme de duree de la tache ya pas photo :p )
Merci pour votre possible réponse car perso jsuis perdu !
Cain... qui voudrait pour une fois éviter de s'acharner sur son frère :p
A voir également:
JProgressBar, rafraichissement en fonction d'une tache a duree inderterminee
cs_tds
Messages postés351Date d'inscriptionmercredi 21 janvier 2004StatutMembreDernière intervention 9 décembre 2004 21 avril 2004 à 11:34
/**
* Returns the number of bytes free on the volume where the given file is located
* @param a file on the volume that the information is requested for
*/
public static long getFreeSpace(File f) throws IOException
{
long bytesFree = -1;
if (System.getProperty("os.name").startsWith("Windows")) {
// create a .bat file to run a directory command
File script = new File(System.getProperty("java.io.tmpdir"), "script.bat");
PrintWriter writer = new PrintWriter(new FileWriter(script, false));
writer.println("dir "" + f.getAbsolutePath() + """);
writer.close();
// get the output from running the .bat file
Process p = Runtime.getRuntime().exec(script.getAbsolutePath());
InputStream reader = new BufferedInputStream(p.getInputStream());
StringBuffer buffer = new StringBuffer();
for (; ; ) {
int c = reader.read();
if (c == -1)
break;
buffer.append( (char) c);
}
String outputText = buffer.toString();
reader.close();
// parse the output text for the bytes free info
StringTokenizer tokenizer = new StringTokenizer(outputText, "\n");
while (tokenizer.hasMoreTokens()) {
String line = tokenizer.nextToken().trim();
// see if line contains the bytes free information
if (line.endsWith("bytes free")) {
tokenizer = new StringTokenizer(line, " ");
tokenizer.nextToken();
tokenizer.nextToken();
bytesFree = Long.parseLong(tokenizer.nextToken().replaceAll(",",""));
}
}
}
if (bytesFree == -1)
throw new UnsupportedOperationException(
"The method getFreeSpace(File) has not been implemented for this operating system.");
return bytesFree;
}
Si j'ai du temps ce soir, je regarderai à trouver une soluce bcp plus élégante, parce que là, c'est assez bourrin.
codessources_Cain
Messages postés8Date d'inscriptiondimanche 14 mars 2004StatutMembreDernière intervention23 juillet 2009 29 avril 2004 à 03:08
Encore merci pour ton aide ! ( oui jlai déjà fait sur #programmation mais tu n'a pas répondu !!! ).
Si tu trouves que c bourrin cke tas fait, jai trouvé pire sur le site de Sun où du code C était proposé et à compiler en DLL dynamik pour une utilisation en JAVA et seulement sous Windaube...