81,095
社区成员
发帖
与我相关
我的任务
分享
URL url=new URL("http://localhost:2008/AJAXFileUpload/bcastr/"+fileName);
System.out.println(url.getFile());
InputStream in;
try {
in = item.getInputStream();// 获得输入数据流文件
// 将该数据流写入到指定文件中
URLConnection urlc= url.openConnection();
urlc.setDoOutput(true);
urlc.connect();
OutputStream out = urlc.getOutputStream();
byte[] buffer = new byte[4096]; // To hold file contents
int bytes_read;
long bytesRead = Long.parseLong((String) session.getAttribute("bytesRead"));// 已读数据大小
while ((bytes_read = in.read(buffer)) != -1) // Read until EOF
{
out.write(buffer, 0, bytes_read);
bytesRead+=(long)bytes_read;
session.setAttribute("bytesRead",String.valueOf(bytesRead));
}