java IO流实现文件上传的demo
2013-05-09 19:21
363 查看
//文件上传
//FileName 为文件名
//file 为文件
//path 为文件的路径,最好是绝对路径
private static void upLoad(String path,String FileName,File file) throws Exception{
File temp = new File(ServletActionContext.getServletContext().getRealPath(path),FileName);
temp.getParentFile().mkdirs();
InputStream ins = null;
OutputStream ous = null;
ins = new FileInputStream(file);
ous = new FileOutputStream(temp);
byte[] bytes = new byte[1024];
int length = 0;
while ((length = ins.read(bytes)) != -1) {
ous.write(bytes, 0, length);
}
if (ous != null) {
ous.close();
}
if (ins != null) {
ins.close();
}
}
本文出自 “码农今天不上班” 博客,请务必保留此出处http://wangpeng1206.blog.51cto.com/6941287/1196745
//FileName 为文件名
//file 为文件
//path 为文件的路径,最好是绝对路径
private static void upLoad(String path,String FileName,File file) throws Exception{
File temp = new File(ServletActionContext.getServletContext().getRealPath(path),FileName);
temp.getParentFile().mkdirs();
InputStream ins = null;
OutputStream ous = null;
ins = new FileInputStream(file);
ous = new FileOutputStream(temp);
byte[] bytes = new byte[1024];
int length = 0;
while ((length = ins.read(bytes)) != -1) {
ous.write(bytes, 0, length);
}
if (ous != null) {
ous.close();
}
if (ins != null) {
ins.close();
}
}
本文出自 “码农今天不上班” 博客,请务必保留此出处http://wangpeng1206.blog.51cto.com/6941287/1196745
相关文章推荐
- JAVA 文件上传下载笔记之使用基本IO流实现上传
- Socket+JDBC+IO实现Java文件上传下载器DEMO详解
- Java【代码】使用jspSmartUpload实现文件上传demo
- java实现文件上传的简单demo
- java操作hadoop hdfs,实现文件上传下载demo
- Java调用uploadify实现文件上传Demo实现
- 【Java】上传文件进度条的实现方法(附demo源码下载)
- Java上传文件进度条的实现方法(附demo源码下载)
- java struts2结合swfupload实现上传文件的demo教程
- Java调用uploadify实现文件上传Demo实现
- Java调用uploadify实现文件上传Demo实现
- Java中使用IO流实现大文件的分裂与合并
- JAVA学习提高之---- FileUpload组件实现多文件上传(JSP+SERVLET)实现
- SpringMVC实现页面和java模型的数据交互以及文件上传下载和数据校验
- 用Java实现FTP批量大文件上传下载
- 用Java写个ftp传输类实现文件的上传和下载,用ikvmc转成dll
- JSch:纯JAVA实现SFTP文件上传和下载
- java学生管理系统(IO流和文件实现)
- Java中实现文件上传下载的三种解决方案 之二
- HTTP POST请求报文格式分析与Java实现文件上传