• Apfeltalk ändert einen Teil seiner Allgemeinen Geschäftsbedingungen (AGB), das Löschen von Useraccounts betreffend.
    Näheres könnt Ihr hier nachlesen: AGB-Änderung
  • Viele hassen ihn, manche schwören auf ihn, wir aber möchten unbedingt sehen, welche Bilder Ihr vor Eurem geistigen Auge bzw. vor der Linse Eures iPhone oder iPad sehen könnt, wenn Ihr dieses Wort hört oder lest. Macht mit und beteiligt Euch an unserem Frühjahrsputz ---> Klick

Datei öffnen

keman

Gast
Wie kann ich einem Java-Programm sagen, es soll eine Datei mit einem bestimmten oder mit dem Standard-Programm dieser Datei öffnen?
 

Daisy

Uelzener Rambour
Registriert
14.01.06
Beiträge
366
Moin Keman,

in "NSWorkspace" gibt's:

openFile
public boolean openFile(String fullPath, String appName, boolean flag)

Opens the file specified by fullPath using the appName application. appName need not be specified with a full path and, in the case of an application wrapper, may be specified with or without the .app extension, as described in “Use of .app Extension”. If appName is null, the default application for the file’s type is used. If flag is true, the sending application is deactivated before the request is sent, allowing the opening application to become the active application. Returns true if the file is successfully opened, false otherwise.

public boolean openFile(String fullPath, String appName)

Opens the file specified by fullPath using the appName application. appName need not be specified with a full path and, in the case of an application wrapper, may be specified with or without the .app extension, as described in “Use of .app Extension”. The sending application is deactivated before the request is sent. Returns true if the file is successfully opened, false otherwise.

public boolean openFile(String fullPath, NSImage anImage, NSPoint point, NSView aView)

Opens the file specified by fullPath using the default application for its type. The Finder provides animation before opening the file to give the user feedback that the file is to be opened. To provide this animation, anImage should contain an icon for the file, and its image should be displayed at point, specified in the coordinates of aView.
The sending application is deactivated before the request is sent. Returns true if the file is successfully opened, false otherwise.

public boolean openFile(String fullPath)

Opens the file specified by fullPath using the default application for its type; returns true if the file was successfully opened, false otherwise. The sending application is deactivated before the request is sent.


Grüße,

Daisy
 

MatzeLoCal

Rheinischer Bohnapfel
Registriert
05.01.04
Beiträge
2.422
keman schrieb:
Wie kann ich einem Java-Programm sagen, es soll eine Datei mit einem bestimmten oder mit dem Standard-Programm dieser Datei öffnen?

Auf Anhieb fällt mir hier nur run.exec() ein. Allerdings fällst Du damit etwas in die Abhängigkeit vom jeweiligen Betriebsystem. Ausserdem musst Du dazu troztdem noch das Programm angeben, mit dem die datei geöffnet werden soll.