在文件上传时,怎么通过选择文件就把文件保存在服务器的临时目录中?
能给我一段代码参考吗?急用

解决方案 »

  1.   

    public String execute() throws Exception {
    //实现上传
    InputStream is = new FileInputStream(file);
    String root = ServletActionContext.getRequest().getRealPath("/upload");
    System.out.println(this.getFileContentType() );
    File deskFile = new File(root,this.getFileFileName());
    OutputStream os = new FileOutputStream(deskFile);
    byte [] bytefer = new byte[400];
    int length = 0 ; 
    while((length = is.read(bytefer) )>0)
    {
    os.write(bytefer,0,length);
    }
    os.close();
    is.close();
    return SUCCESS;
    }