我在写一个用JSP对EXCEL文件操作的程序,根据网上前辈的指点,小有成果,
不过现在有个问题是,该文件我只能用绝对路径访问,程序片段如下:
InputStream is = new FileInputStream("E:/lx/kq.xls");
在这里参数为("E:/lx/kq.xls"),也就是我必须把文件放在E盘下面的名称
为lx的文件夹里面才能访问得到,而我现在想要的是文件随便放在我的电脑的
甚么地方也能访问得到,不知道该如何实现。望哪个高手指点迷津,不胜感激!

解决方案 »

  1.   

    保存文件的时候 就取出路径不就行了 String file = "xxxxxx";
    InputStream   is   =   new   FileInputStream(file); 
      

  2.   

    汗,要是随便文件在什么位置都能访问到,那windows的那个文件搜索还干什么用。。
      

  3.   

    那我要是用个<input type="file">之类的东西浏览,然后选择到该文件,该如何才能对其操作呢?另:像楼上所说放项目里,用相对路径,具体该怎么做。能否写详细点。谢谢
      

  4.   


    InputStream   fi   =   this.getClass().getResourceAsStream( "/ "+kq.xls); //路径自己配置
      

  5.   

    jsp:
    <input  name='file1' type= "file ">actionform:
    public class FileUpLoadActionForm
        extends ActionForm {
      public FileUpLoadActionForm() {
      }  private FormFile file1;
      public ActionErrors validate(ActionMapping actionMapping,
                                   HttpServletRequest httpServletRequest) {
        /**@todo: finish this method, this is just the skeleton.*/
        return null;
      }  public void reset(ActionMapping actionMapping,
                        HttpServletRequest httpServletRequest) {  }  public FormFile getFile1() {
        return file1;
      }  
      public void setFile1(FormFile file1) {
        this.file1 = file1;
      }}  action:public ActionForward upload(ActionMapping actionMapping,
    ActionForm actionForm, HttpServletRequest httpServletRequest,
    HttpServletResponse httpServletResponse) throws Exception {
    FileUpLoadActionForm fileForm = (FileUpLoadActionForm)       actionForm;fileForm.getFile1();
    //实现你的代码
    }