java - open pdf file located in a ressource folder -


i'm trying open pdf located in ressource folder application. work on emulator nothing happens when try on exported application. i'm guessing i'm not using rigth path not see i'm wrong. getressource method works images.

here code snippet :

public void openpdf(string pdf){     if (desktop.isdesktopsupported()) {         try {             url monurl  = this.getclass().getresource(pdf);             file myfile = new file(monurl.touri());             desktop.getdesktop().open(myfile);           } catch (ioexception ex) {             // no application registered pdfs          } catch (urisyntaxexception e) {             // todo auto-generated catch block             e.printstacktrace();         }     } } 

i'm referring pdf variable way : "name_of_the_file.pdf"

edit: i've pasted whole method

ok, solved it. file being located in jar, way through inputsteam/outstream , creating temp file.

here final code, works great :

public void openpdf(string pdf){         if (desktop.isdesktopsupported())            {                inputstream jarpdf = getclass().getclassloader().getresourceasstream(pdf);              try {                 file pdftemp = new file("52502hpa3_electra_plus_fra.pdf");                 // extraction du pdf qui se situe dans l'archive                 fileoutputstream fos = new fileoutputstream(pdftemp);                 while (jarpdf.available() > 0) {                       fos.write(jarpdf.read());                 }   // while (pdfinjar.available() > 0)                 fos.close();                 // ouverture du pdf                 desktop.getdesktop().open(pdftemp);             }   // try              catch (ioexception e) {                 system.out.println("erreur : " + e);             }   // catch (ioexception e)         }     } 

Comments

Popular posts from this blog

linux - Does gcc have any options to add version info in ELF binary file? -

android - send complex objects as post php java -

charts - What graph/dashboard product is facebook using in Dashboard: PUE & WUE -