Share on Google+Share on Google+

Path of source code

Advertisement
This tutorial demonstrate how to get the path of your source code

Description: 

This example demonstrate how to get the path of your java program file. The URI represents the abstract pathname and URL construct from URI.

Code:

import java.io.*;
import java.net.*;

public class FileLocation {
  public static void main(String args[]) throws MalformedURLException {
    File file = new File("FileLocation");
    URL url = file.toURI().toURL();
    System.out.printf("%s", url);
  }
}

Output:

Advertisements

Advertisement

Posted on: April 21, 2010 If you enjoyed this post then why not add us on Google+? Add us to your Circles

Share this Tutorial Follow us on Twitter, or add us on Facebook or Google Plus to keep you updated with the recent trends of Java and other open source platforms.