我在Windows XP下使用Java . 为了在旧的爱普生打印机中打印,我使用 FileOutputStream . 例如:

ostream = new FileOutputStream(printer);
pstream = new PrintStream(ostream);

//reset default settings
pstream.print(ESC);
pstream.print(AT);

要初始化 FileOutputStream ,我使用打印机的网络名称,例如 "\\Server\Printer" . 如果计算机连接到网络,这可以正常工作,但如果没有可用的网络,我会收到带有消息"The network location cannot be reached. For information about network troubleshooting, see Windows Help"的 FileNotFoundException . Server is the name of the computer where I'm running the app. Anyway, if I use "\localhost\Printer" I get the same error.

我尝试了Windows文件浏览器,看看我是否在那里遇到此错误,以防这是Windows的事情 . 如果我尝试输入一些本地共享文件夹( \\Server\Folder )而没有连接到网络,我得到相同的错误 . 但是, if I write \Server\Printer the file explorer opens the printer.

那么, how can I initialize the FileOutputStream when there is no network available?

EDIT: 我有几台打印机通过LPT1和USB端口连接到服务器 . 同一程序在其他计算机上运行,这就是我使用打印机共享名称的原因 . 但是,如果有人从网络上拔下服务器,我希望我的程序在服务器上继续正常工作 .

我有这个运行多年,但几天前我想改变一个路由器,为此我断开了服务器 . 然后,我收到了这个错误,但是当打印机连接到服务器时,无论网络可用性如何,程序都应该在服务器上运行 .