(Java) InputStream vers OutputStream

banyate -  
 Utilisateur anonyme -
Salut , Voila j'ai un bout de code que j'essaie d'adapter a mes besoins , en clair sa prend un ficher et le redirige vers un outputStream , ce que je voudrais c'est rediriger des fichiers depuis une connexion ( URLConnection ) , comment s'y prendre ?

Le bout de code en question :
        Headers h = t.getResponseHeaders();
        h.add("Content-Type", "application/pdf");
        OutputStream os = t.getResponseBody();
        
        
        // a PDF 
        File file = new File ("c:/test.txt");
        byte [] bytearray  = new byte [(int)file.length()];
        FileInputStream fis = new FileInputStream(file);
        BufferedInputStream bis = new BufferedInputStream(fis);
        bis.read(bytearray, 0, bytearray.length);

        // ok, we are ready to send the response.
        t.sendResponseHeaders(200, file.length());
        
        os.write(bytearray,0,bytearray.length);
        os.close();


Merci
A voir également:

1 réponse

Utilisateur anonyme
 
Salut,

Tu reçois le fichier depuis l'URLConnection ou tu veux l'evoyer via celle-ci?

HackTrack
0