How to Import a Package From API in Java


In this example we will show how to import a package from API in Java.

Source Code

package com.beginner.examples;

import java.io.*; // import a package

public class ImportPackage {
  public static void main(String[] args) {
      File f = new File("test.txt");
      if (f.exists()) { // judge whether the file exists
        System.out.println("YES");
      } else {
        System.out.println("NO");
      }
  }
}

Output:

NO
Subscribe
Notify of
guest
0 Comments
Inline Feedbacks
View all comments