Open PDF file on the fly from a Java application

前端 未结 6 1896
逝去的感伤
逝去的感伤 2020-12-01 09:06

Is there any way to have a code that opens a PDF file in Java application in a platform independant way? I mean using a batch file in Windows could do that. Is there any oth

6条回答
  •  心在旅途
    2020-12-01 09:44

    Use this to open pdf file using java

    File file = new File(filepath);
        if (file.toString().endsWith(".pdf")) 
            Runtime.getRuntime().exec("rundll32 url.dll,FileProtocolHandler " + file);
        else {
            Desktop desktop = Desktop.getDesktop();
            desktop.open(file);
    }
    

    This code is used to open your pdf and other files.

提交回复
热议问题