One, epub ebook format
Related materials and source code are available for download in the link: Http://pan.baidu.com/s/1bnm8YXT
Including
1, Java Project Engineering Test_epub, which includes a jar package and an epub ebook mybook.epub
2. epub Related JAR Package
3, e-book Mybook.epub
The EPUB format is not carefully described here, it is emphasized here that the EPUB format is a compressed format, just change the suffix to. zip or. rar, unzip to see the contents of the file.
Second, Java parsing. epub Format ebook, the specific implementation code is as follows. Wrote a simple HelloWorld program, added the corresponding jar package.
Program Description:
1, read the Epub/mybook.epub file.
2, modify the title in the metadata
3. Export the new. epub File to the project directory. File name Mynewbook.epub
By extracting the Mynewbook.epub file, you can see that the <dc:title> tag content in the <docTitle> and Content.opf in the Toc.ncx file has been modified.
Package Com.hk;import Java.io.fileinputstream;import Java.io.filenotfoundexception;import Java.io.FileOutputStream ; Import Java.io.ioexception;import java.io.inputstream;import java.io.outputstream;import java.util.ArrayList; Import Java.util.list;import Nl.siegmann.epublib.domain.book;import Nl.siegmann.epublib.epub.epubreader;import Nl.siegmann.epublib.epub.epubwriter;public class Test {public static void main (string[] args) {System.out.println (" Hello World "); Epubreader Epubreader = new Epubreader ();//Processing IO stream path String currentpath = Thread.CurrentThread (). GetClass (). GetResource ( "/"). ToString (); String Epubpath = Currentpath + "Epub/mybook.epub"; Epubpath = epubpath.substring (6, Epubpath.length ()); Epubpath = Epubpath.replace ("/", "//"); System.out.println (Epubpath); Read epub file Book book = null;try {inputstream inputstr = new FileInputStream (epubpath); book = Epubreader.readepub (INPUTSTR) ;} catch (FileNotFoundException e) {e.printstacktrace ();} catch (IOException e) {E.printStackTrace ();} Set the title.//in the epub file to modify the <dc:title> tag content in <docTitle> and Content.opf in the Toc.ncx file. list<string> titleslist = new arraylist<string> (); Titleslist.add ("Test book"); Book.getmetadata (). Settitles (titleslist);//write epubepubwriter epubwriter = new Epubwriter (); try {outputstream ouput = new FileOutputStream ("Mynewbook.epub"); Epubwriter.write (book, ouput);} catch (FileNotFoundException e) {e.printstacktrace ();} catch (IOException e) {e.printstacktrace ()}}}
If you do not understand and write the wrong place, please comment.
Java parsing epub Format ebook, HelloWorld program, with source program and related jar package