繁体   English   中英

在打印之前打开文件?

[英]File opens before printing?

嗨,我正在使用此程序来打印我的文件,它会在打印前打开文件?我要删除该文件。有什么建议吗?

import java.awt.Desktop;
import java.io.File;
import java.io.IOException;

public class PrintFile {    

  public static void fileToPrint(File fis) {
    try {
      Desktop desktop = null;
      if (Desktop.isDesktopSupported())
      {

        desktop = Desktop.getDesktop();  

      }   
       desktop.print(fis);  
       System.out.print("Printing Document");
    }
    catch (IOException ioe)
    {
      ioe.printStackTrace();
    }

  }
}

AWT中的Desktop API使用系统的本机功能(在本例中为Windows。)JVM可能会使用“ print”命令在文件上调用ShellExecute / ShellExecuteEx。 Windows处理该命令的方式是在注册表中搜索文件类型的print命令,然后运行该命令。 对于大多数文件类型,这将导致处理该文件的应用程序打开,然后自动执行打印命令。

简而言之,如果您不打开应用程序,我认为您将无法使用Desktop API。 您需要自己进行所有打印(当然,这很困难。)

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM