Lecture/copie contenu d'1 fichier avec java

ratouch Messages postés 10 Statut Membre -  
KX Messages postés 19031 Statut Modérateur -
Bonjour,
Je désire faire la lecture du contenu entier d'un fichier d'extension quelconque puis copier ce contenu dans un autre fichier. Et je veux utiliser java pour cette opération.
Comment ça se fait?



A voir également:

1 réponse

KX Messages postés 19031 Statut Modérateur 3 020
 
Voici une manière de faire :

public static void copyFile(String in, String out) throws IOException 
{
    FileChannel inChannel = new FileInputStream(in).getChannel();
    FileChannel outChannel = null;
    
    try 
    {
    	outChannel = new FileOutputStream(out).getChannel();
    	inChannel.transferTo(0, inChannel.size(), outChannel);
    } 
    catch (IOException e) 
    {
        throw e;
    }
    finally
    {
        if (inChannel != null) inChannel.close();
        if (outChannel != null) outChannel.close();
    }
}

NB. inChannel.size() "limite" l'utilisation de cette méthode à 8 Eo...
0