next up previous contents
suivant: Reader Writer monter: Entrées/Sorties précédent: Stream   Table des matières

InputStream, OutputStream

InputStream et OutputStream sont les classes abstraites pour les flots de byte. La méthode read lit un byte (mais retourne un entier). La méthode write écrit un byte (mais a un int comme argument).



transparent
Compter les octets...


//  Byte stream
import java.io.*;
class TailleOctet {
    public static void main(String[] st) throws IOException{
        InputStream in;
        int s=0;
        if(st.length == 0)
            in = System.in;
        else
            in = new FileInputStream(st[0]);
        while(in.read() != -1) s++;
        System.out.println(st[0]+":"+s+" octets");
    }
}




transparent
Copie


//  Byte stream
import java.io.*;
class  Copie{
    public static void main(String[] st) throws IOException{
        InputStream in; OutputStream out; int c;
        if(st.length == 0){ in = System.in; out =System.out;
        }
        else{
            in = new FileInputStream(st[0]);
            if(st.length == 1)
                out = System.out;
            else
                out = new FileOutputStream(st[1]);
        }
        while((c=in.read()) != -1) out.write(c);
    }
}





Hugues Fauconnier 2002-01-11