View RSS Feed

Java Socket

Socket programming and networking examples in Java.

  1. URL's to Local Files

    by , 04-25-2012 at 11:42 PM
    In local file system, files could be accessed by using URL class. Hence, file opening is an easy task done by URL class, if your code is needed to find out whether file came from local file system or network.
    How a file could be opened in local file system by URL class is shown in this example:
    URL url = new URL("file:/c:/data/test.txt");
    Java Code:
    URLConnection urlConnection = url.openConnection();
    InputStream input = urlConnection.getInputStream();