简体   繁体   English

在远程数据库中打开文件

[英]Opening file in Remote Database

I have java desktop application where I have file upload and view feature.我有 java 桌面应用程序,其中有文件上传和查看功能。 Here is my code for opening a file这是我打开文件的代码

 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;
    }
}

This is perfectly working in MAC OS but when I am running in windows 7 PC it won't open files.这在 MAC OS 中完美运行,但是当我在 Windows 7 PC 中运行时,它不会打开文件。 Following are the error messages;以下是错误信息;

Adobe reader error: "There was an error opening this document. This file is already open or in use by another application" Adobe 阅读器错误: “打开此文档时出错。此文件已打开或已被其他应用程序使用”

Windows Photo viewer error message: "Windows photo viewer can't open this picture because the picture is being edited in another program" Windows 照片查看器错误消息: “Windows 照片查看器无法打开此图片,因为该图片正在另一个程序中编辑”

Paint error message: "A sharing violation occurred while accessing ....."绘制错误消息: “访问时发生共享冲突......”

Please help请帮忙

Thank You谢谢你

Windows can't cope with the idea of two programs using a file at once, presumably due to its DOS single-user origins. Windows 无法处理两个程序同时使用一个文件的想法,大概是由于它的 DOS 单用户起源。 Make sure that when you save the file, you close it before you call your open() method.确保在保存文件时,调用open()方法之前将其关闭。

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

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