Hello,
J'ai créé un bout de code tout simple pour copier un fichier...
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
|
public static void copy(File from, File to)
{
FileChannel fromChan = null;
FileChannel toChan = null;
try{
try {
FileInputStream fromStr = new FileInputStream(from);
fromChan = fromStr.getChannel();
} catch (FileNotFoundException e) {
log.error("Unable to read input file: "+e.getMessage());
}
try {
toChan = new FileOutputStream(to).getChannel();
} catch (FileNotFoundException e) {
log.error("Unable to create output file: "+e.getMessage());
}
try {
fromChan.transferTo(0, fromChan.size(), toChan);
} catch (IOException e) {
log.error("Unable to copy file: "+e.getMessage());
}
}catch(Exception e){
log.error("Unable to copy file: "+e.getMessage());
}finally {
try {
fromChan.close();
toChan.close();
} catch (IOException e) {
log.error("Error closing file"+e.getMessage());
}
} |
Seulement le programme se bloque (ne fais rien) sur l'instruction
fromChan = fromStr.getChannel();
, comme si le fichier était déjà utilisé, ce qui à première vue n'est pas le cas. Il n'est en tout cas pas ouvert par un programme windows... Et pas d'autre process java en arrière plan...
Une idée?
Merci d'avance.
A+
Partager