文件下载 (java)自己的一些总结
package com.down.servlet;
import java.io.BufferedInputStream;
import java.io.File;
import java.io.FileInputStream;
import java.io.IOException;
import java.io.InputStream;
import java.net.URLEncoder;
import javax.servlet.ServletException;
import javax.servlet.ServletOutputStream;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
/**
* Servlet implementation class DownServlet
*/
public class DownServlet extends HttpServlet {
private static final long serialVersionUID = 1L;
/**
* @see HttpServlet#HttpServlet()
*/
public DownServlet() {
super();
// TODO Auto-generated constructor stub
}
/**
* @see HttpServlet#doGet(HttpServletRequest request, HttpServletResponse response)
*/
protected void doGet(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
doPost(request, response);
}
/**
* @see HttpServlet#doPost(HttpServletRequest request, HttpServletResponse response)
*/
protected void doPost(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
File downFile = new File ("c:\\OriRevision.doc");
InputStream is = new FileInputStream(downFile);
response.setContentType("text/plain;charset=UTF-8");
response.setBufferSize(100 * 1024);
BufferedInputStream bufInputStream = null;
response.setHeader("Cache-Control", "public");
ServletOutputStream os = response.getOutputStream();
//设置现在word正文的相关信息
response.setHeader("Content-Disposition", "inline; filename="+ URLEncoder.encode("test.doc", "UTF-8"));
if(is != null){
byte[] b = new byte[10240];
int index = 0;
os = response.getOutputStream();
bufInputStream = new BufferedInputStream(is);
while((index = bufInputStream.read(b)) != -1){
os.write(b, 0, index);
}
response.flushBuffer();
}
}
}
相关文档:
49.文本查找替换
//import java.nio.*;
String s1=%%1;
String s2=%%2;
String s3=%%3;
int pos=%%4;
/*变量i和j分别表示主串和模式串中当前字符串的位置,k表示匹配次数*/
int i,j,k=0;
i = pos;
j = 0;
//将s ......
73.FTP下载
/*
import sun.net.ftp.FtpClient;
import java.io.*;
import sun.net.*;
*/
//如果文件在某个目录下,则加入fc.cd("foodir");
//比如要下载ftp://ftp.xx.com/index.html则:
try
{
FtpClient fc=new FtpClient("ftp.xx.com");
fc.logi ......
1.创建测试表
create table users(
userid int primary key,
username varchar2(20),
userpwd varchar2(20)
);
insert into users values(1,'test','test');
insert into users values(2,'test','test');
insert into users values(3,'test','test');
insert into users values(4,'test','test');
insert i ......
21天学通Java6 下载地址 http://d.download.csdn.net/down/2031000/bolike(只有源代码)
<<21天学通Java 2(第二版)>>(中英文版PDF)+附书源码 下载地址 http://www.zzx8.com/html/c16246.html(似乎中英文的不对应,看中文还是看英文的?) ......