java上传各种格式pdf,xls,doc等

            String sll = path;
            //获取字符后四位
            if(sll.substring(sll.length()-4, sll.length()).equals(".xls")) {
                // 获取Excel文件对象
                HSSFWorkbook workBook = new HSSFWorkbook(stream);
            }else if(sll.substring(sll.length()-4, sll.length()).equals(".xlsx")) {
                //xlsx
                HSSFWorkbook workBook = new HSSFWorkbook(stream);
            }else if(sll.substring(sll.length()-5, sll.length()).equals(".docx")) {
                //用来读取docx文件
                XWPFDocument doc = new XWPFDocument(stream);
            }else if(sll.substring(sll.length()-4, sll.length()).equals(".doc")){
                //doc
                 HWPFDocument doc = new HWPFDocument(stream);
            }else if(sll.substring(sll.length()-4, sll.length()).equals(".pdf")) {
                //pdf
                 PDDocument pd = PDDocument.load(stream);
            }

 

posted @ 2019-09-24 17:16  闫超辉  阅读(2240)  评论(0编辑  收藏  举报