01 import java.io.*;
02
03 public class ServeFile {
04
05 // táto metóda pošle obsah súboru do výstupného prúdu
06 public static void returnFile(String file, OutputStream out)
07 throws FileNotFoundException, IOException {
08 FileInputStream fis = null;
09 try {
10 fis = new FileInputStream(file);
11 byte[] buf = new byte[4 * 1024];
12 int bytesRead;
13 while ((bytesRead = fis.read(buf)) != -1) {
14 out.write(buf, 0, bytesRead);
15 }
16 }
17 finally {
18 if (fis != null) fis.close();
19 }
20 }
21 }
|