Monday, 3 June 2019

Java: Open a file


Using desktop.open method, you can open a file in Java.

Desktop desktop = Desktop.getDesktop();
File file = new File("data.docx");
desktop.open(file);

App.java
package com.sample.app;

import java.awt.Desktop;
import java.io.File;
import java.io.IOException;

public class App {

 public static void main(String args[]) throws IOException {

  Desktop desktop = Desktop.getDesktop();
  File file = new File("data.docx");
  desktop.open(file);

 }
}


You may like

No comments:

Post a Comment