Fri Apr 06, 2007 9:59 am
/*
By : Sami & El-dib
*/
<%@ page import="java.io.FileInputStream" %>
<%@ page import="java.io.BufferedInputStream" %>
<%@ page import="java.io.File" %>
<%@ page import="java.io.IOException" %>
<%
// you can get your base and parent from the database
String base="e1";
String parent="e2";
String filename=parent+"_codemiles.zip";
// you can write http://localhost
String filepath="http://www.codemiles.com/example/"+base+"/";
BufferedInputStream buf=null;
ServletOutputStream myOut=null;
try{
myOut = response.getOutputStream( );
File myfile = new File(filepath+filename);
//set response headers
response.setContentType("text/plain");
response.addHeader(
"Content-Disposition","attachment; filename="+filename );
response.setContentLength( (int) myfile.length( ) );
FileInputStream input = new FileInputStream(myfile);
buf = new BufferedInputStream(input);
int readBytes = 0;
//read from the file; write to the ServletOutputStream
while((readBytes = buf.read( )) != -1)
myOut.write(readBytes);
} catch (IOException ioe){
throw new ServletException(ioe.getMessage( ));
} finally {
//close the input/output streams
if (myOut != null)
myOut.close( );
if (buf != null)
buf.close( );
}
%>
Tue Apr 17, 2007 12:58 am
Wed Apr 01, 2009 5:44 pm
Thu May 06, 2010 11:30 am
Fri May 14, 2010 5:14 am
Mon May 17, 2010 4:24 pm
Tue Jul 13, 2010 2:25 pm
Thu Jul 15, 2010 7:14 am
Fri Aug 12, 2011 4:39 am
Tue Aug 23, 2011 6:03 am
<html>
<head>
<%@ page import="java.io.FileInputStream" %>
<%@ page import="java.io.BufferedInputStream" %>
<%@ page import="java.io.File" %>
<%@ page import="java.io.IOException" %>
<%@ page import="java.util.List" %>
<%@ page import="java.net.URLConnection" %>
<%@ page import="java.io.BufferedOutputStream" %>
<%@ page import="java.util.zip.ZipOutputStream" %>
<%@ page import="java.io.FileOutputStream" %>
<%@ page import="java.util.zip.ZipEntry" %>
<%@ page import="java.io.InputStream" %>
<%@ page import="java.net.URL" %>
<%
Object filename = request.getAttribute("filename");
ZipOutputStream zipOut = null;
BufferedInputStream buf = null;
ServletOutputStream myOut = null;
String tempFolder = System.getProperty("user.dir")+ File.separator +"upload"+ File.separator + "temp.zip";
try {
File inputFolder = new File(filename.toString());
File outFolder = new File(tempFolder);
zipOut = new ZipOutputStream(new BufferedOutputStream(
new FileOutputStream(outFolder)));
byte[] data = new byte[1000];
String files[] = inputFolder.list();
for (int i = 0; i < files.length; i++) {
buf = new BufferedInputStream(new FileInputStream(
inputFolder.getPath() + "/" + files[i]), 1000);
zipOut.putNextEntry(new ZipEntry(files[i]));
int count;
while ((count = buf.read(data, 0, 1000)) != -1) {
zipOut.write(data, 0, count);
}
zipOut.closeEntry();
}
zipOut.flush();
zipOut.close();
myOut = response.getOutputStream();
response.setContentType("binary/data");
response.addHeader("Content-Disposition",
"attachment; filename=XMLs.zip");
try {
URL url = new URL("file:///" + outFolder);
URLConnection con = url.openConnection();
buf = new BufferedInputStream(con.getInputStream());
int readByte = 0;
while ((readByte = buf.read()) != -1) {
myOut.write(readByte);
}
buf.close();
} catch (Exception e) {
}
} catch (Exception ioe) {
throw new ServletException(ioe.getMessage());
} finally {
if (myOut != null)
myOut.close();
if (buf != null)
buf.close();
}
%>
</head>
</html>
Codemiles.com is a participant in the Amazon Services LLC Associates Program, an affiliate advertising program designed to provide a means for sites to earn advertising fees by advertising and linking to Amazon.com
Powered by phpBB © phpBB Group.