PackageWorld ;ImportJava.io.File;ImportJava.io.FileInputStream;Importjava.io.FileNotFoundException;ImportJava.io.FileOutputStream;Importjava.io.IOException;Importjava.util.List;Importorg.apache.poi.POIXMLDocument;ImportOrg.apache.poi.POIXMLTextExtractor;ImportOrg.apache.poi.openxml4j.opc.OPCPackage;ImportOrg.apache.poi.xwpf.extractor.XWPFWordExtractor;Importorg.apache.poi.xwpf.usermodel.XWPFDocument;ImportOrg.apache.poi.xwpf.usermodel.XWPFPictureData;Importjava.io.IOException;ImportJava.io.InputStream;ImportJava.io.Reader;ImportWorld.user;Importorg.apache.ibatis.io.Resources;Importorg.apache.ibatis.session.SqlSession;Importorg.apache.ibatis.session.SqlSessionFactory;ImportOrg.apache.ibatis.session.SqlSessionFactoryBuilder; Public classWorld { Public Static voidMain (string[] args) {String connect=""; String Path= "D:\\123.docx"; File File=NewFile (path); Try{FileInputStream fis=Newfileinputstream (file); Xwpfdocument Document=Newxwpfdocument (FIS); Xwpfwordextractor Xwpfwordextractor=NewXwpfwordextractor (document); String text=Xwpfwordextractor.gettext (); System.out.println (text); List<XWPFPictureData> piclist =document.getallpictures (); for(Xwpfpicturedata pic:piclist) {System.out.println (Pic.getpicturetype ()+ File.separator +pic.suggestfileextension ()+file.separator+pic.getfilename ()); Connect= Pic.getpicturetype () + File.separator +pic.suggestfileextension ()+file.separator+Pic.getfilename (); byte[] Bytev =Pic.getdata (); FileOutputStream Fos=NewFileOutputStream ("d:\\web\\" +pic.getfilename ()); Fos.write (Bytev); } fis.close (); String Resource= "Conf.xml"; InputStream is= World.class. getClassLoader (). getResourceAsStream (Resource); Sqlsessionfactory sessionfactory=NewSqlsessionfactorybuilder (). Build (IS); Sqlsession Session=sessionfactory.opensession (); String Statement= "World.userMapper.insertUser1"; User User2=NewUser (); User2.setname (text); User2.setage (connect); intCount = Session.insert ("World.userMapper.add", User2); Session.commit (); System.out.println (count); } Catch(IOException e) {e.printstacktrace (); } }}
Java reads the world picture and stores the picture path in the database