1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42
| package gseSrc.file;
import java.awt.Desktop;
import java.io.File;
import java.io.IOException;
import java.io.InputStream;
import org.apache.commons.io.FileUtils;
/**
* <h2>About</h2>
* Allow to open pdf<br />
* <br />
*
*/
public class Openpdf {
public static void access(String fileNameInJAR, String extension) {
if(Desktop.isDesktopSupported()){
if(Desktop.getDesktop().isSupported(Desktop.Action.OPEN)){
try {
InputStream pdfInJar = Openpdf.class.getClass().getResourceAsStream(fileNameInJAR);
File tempFile = File.createTempFile("JAR_", extension);
System.out.println("chemin temp : " +tempFile.getAbsolutePath());
FileUtils.copyInputStreamToFile(pdfInJar, tempFile);
pdfInJar.close();
Desktop.getDesktop().open(tempFile);
} catch (IOException e) {
// TODO Auto-generated catch block
e.printStackTrace();
}
}
}
}
} |
Partager