请问如何在上传文件的时候,取出不带扩展名的文件名
谢谢

解决方案 »

  1.   

    public static void main(String args[]){
      String a = "c:\\sdfdsa\\a.jpg";
      a = a.substring(a.lastIndexOf("\\")+1,a.length());
      System.out.println(a);//a.jpg
      a = a.substring(0,a.lastIndexOf(".")).replace(" ", "");
      System.out.println(a);//a
      }
      

  2.   

    用smartupload类在简单的字符串提取就ok了,很容易的
      

  3.   

    SmartUpload su = new SmartUpload();
    su.initialize(pageContext);
    su.upload();
    String name = su.getRequest().getParameter("Name"); //得到上传的文件名
      

  4.   

    SmartUpload su = new SmartUpload();
    //上传初始化 
    su.initialize(pageContext);
    //设定上传限制 
    //1.限制每个上传文件的最大长度。 
    su.setMaxFileSize(1000000);
    //2.限制总上传数据的长度。 
    //su.settotalmaxfilesize(20000); 
    //3.设定允许上传的文件(通过扩展名限制),仅允许doc,txt文件。 
    //su.setAllowedFilesList("doc,txt"); 
    //4.设定禁止上传的文件(通过扩展名限制),禁止上传带有exe,bat, jsp,htm,html扩展名的文件和没有扩展名的文件。 
    //su.setdeniedfileslist("exe,bat,jsp,htm,html,,"); 
    //上传文件 
    su.upload();
    //将上传文件全部保存到指定目录
    String filetype = su.getFiles().getFile(0).getFileExt();
    bookimage = "/image/book/" + book.getBookisbn() + "."+ filetype;
    SmartFile f1 = su.getFiles().getFile(0);
    //上传文件,成功返回1
    try {
    f1.saveAs(bookimage);
    count = 1;
    } catch (IllegalArgumentException e) {
    out.print("图片上传出错了" + e);
    }
    如果想提取文件名只需
    String filename = su.getFiles().getFile(0);
    filename = filename.subsring(0,filename.lastindex("."));