Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Launch file from Java

Tags:

java

io

launch

I want to launch a file(a document) from a Java program and phase the following requirements:

  • Method must be applicabale on Mac, Win and Linux systems
  • I am not allowed to use "Runtime.getRuntime().exec("cmd.exe /C +"filename");
  • The file I am launching needs to be either of .doc / .docx / .rtf

The file is created runtime, a result from a report being created. Any good practices?

like image 770
Tor-Morten Avatar asked May 11 '09 12:05

Tor-Morten


People also ask

How do you open a file with Java?

Java FileInputStream class is used to open and read a file. We can open and read a file by using the constructor of the FileInputStream class. The signature of the constructor is: public FileInputStream(File file) throws FileNotFoundException.

How do I open a launch file?

roslaunch is used to open launch files. This can be done by either specifying the package the launch files are contained in followed by the name of the launch file, or by specifying the file path to the launch file. Note: roslaunch will also start roscore if no master has been set.

How do you execute in Java?

C++ Programming Type 'javac MyFirstJavaProgram. java' and press enter to compile your code. If there are no errors in your code, the command prompt will take you to the next line (Assumption: The path variable is set). Now, type ' java MyFirstJavaProgram ' to run your program.


1 Answers

Use Java Desktop API.

Desktop.getDesktop().open(new File(yourfilename));
like image 159
Joonas Pulakka Avatar answered Sep 20 '22 15:09

Joonas Pulakka