Java I/O How to - Create file path by connecting folder strings








Question

We would like to know how to create file path by connecting folder strings.

Answer

import java.io.File;
//from   w  w w.java  2 s .  c o m
public class Main {

  public static void main(String[] args) {
    String filePath = File.separator + "Java" + File.separator + "IO";
    File file = new File(filePath);
    System.out.println(file.getPath());
  }
}

The code above generates the following result.