Guest
Public paste!

Untitled

By: a guest | Mar 16th, 2010 | Syntax: None | Size: 0.80 KB | Hits: 36 | Expires: Never
Copy text to clipboard
  1. private static void fileDownload (Socket s, String t, String z) throws IOException {
  2.                
  3.                 BufferedOutputStream out = new BufferedOutputStream (s.getOutputStream());
  4.                 File F = new File (rootPath.concat(t));
  5.                 File [] lista = F.listFiles();
  6.                 if (lista != null) {
  7.                         for (int i = 0; i < lista.length; i++) {
  8.                                 if (lista[i].getName().equals(z)) {
  9.                                         File f = new File (rootPath.concat(t).concat("/").concat(z));
  10.                                         BufferedInputStream fin = new BufferedInputStream(new FileInputStream(f));
  11.                                         copia(fin, out, 10000);
  12.                                 }
  13.                         }
  14.                 }
  15.         }
  16.        
  17.         public static void copia (InputStream in, OutputStream out, int bufferSize) throws IOException {
  18.        
  19.                 byte[] buffer = new byte[bufferSize];
  20.         int n;
  21.         while ((n = in.read(buffer)) > 0) {
  22.             out.write(buffer, 0, n);
  23.         }
  24.     }