我现在有一个地址,绝对路径,表示一个文件是所在,我现在想根据这个路径把文件上传到服务器上,应该怎么写?
以前是通过file控件选出文件,现在是直接有个地址~!
请教高手~!
------解决方案--------------------
InputStream in=file.getInputStream();
OutputStream out=new FileOutputStream(文件路径+ "/ "+文件名);
int read=0;
byte[] buffer=new byte[8192];
while((read=in.read(buffer,0,8192))!=-1){
out.write(buffer,0,read);
}
out.close();
in.close();
------解决方案--------------------
用jspsmart.upload就可以拉
------解决方案--------------------
没错
用这个com.jspsmart.upload.SmartUpload
------解决方案--------------------
jspSmartUpload比较好用
------解决方案--------------------
用这个改改试试
String path = this.getServletContext().getRealPath( "\\ ");
//定义文件上传对象upload
com.jspsmart.upload.SmartUpload upload = new SmartUpload();
//将Servlet配置和携带上传数据的request对象和response对象传递给upload对象
upload.initialize(this.getServletConfig(), request, response);
// try {
// upload.setDeniedFilesList( "exe,txt,jsp,htm,html ");
// } catch (Exception e) {
// response.sendRedirect( " ");
// }
try {
//接受客户端提交的上传数据
upload.upload();
com.jspsmart.upload.Request req = upload.getRequest();
String file = req.getParameter( "file ");
//创建文件目录
// File file = new File( "/ ");
// file.mkdir();
// FileOutputStream output = new FileOutputStream( "/ "+temp_category+ "/ ");
// output.close();
//保存客户端提交的上传文件
upload.save( "/ ",upload.SAVE_VIRTUAL);