我有 java 桌面应用程序,其中有文件上传和查看功能。 这是我打开文件的代码
public static boolean open(File file) {
OSDetector osdetector = new OSDetector();
try {
if (osdetector.isWindows()) {
Runtime.getRuntime().exec(new String[]{"rundll32", "url.dll,FileProtocolHandler",
file.getAbsolutePath()});
return true;
} else if (osdetector.isLinux() || osdetector.isMac()) {
Runtime.getRuntime().exec(new String[]{"/usr/bin/open",
file.getAbsolutePath()});
return true;
} else // Unknown OS, try with desktop
if (Desktop.isDesktopSupported()) {
Desktop.getDesktop().open(file);
return true;
} else {
return false;
}
} catch (Exception e) {
e.printStackTrace(System.err);
return false;
}
}
这在 MAC 操作系统中运行良好,但当我在 Windows 7 PC 中运行时,它无法打开文件。 以下是错误信息;
Adobe 阅读器错误:“打开此文档时出错。此文件已打开或正在被其他应用程序使用”
Windows 照片查看器错误消息:“Windows 照片查看器无法打开此图片,因为该图片正在另一个程序中编辑”
绘制错误消息:“访问时发生共享冲突......”
请帮忙
谢谢
最佳答案
Windows 不能处理两个程序同时使用一个文件的想法,大概是由于它的 DOS 单用户起源。确保在保存文件时, 在调用 open()
方法之前将其关闭。
关于java - 在远程数据库中打开文件,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/42978941/