import java.net.URL;
import java.net.URLConnection;
import java.nio.file.Path;
import java.nio.file.Paths; 

public class FileUrlLeakRepro {
    public static void main(String[] args) throws Exception {
        // Point to an existing file
        Path p = Paths.get("\\Test\\FileDescriptorLeak\\sample.txt");
        URL url = p.toUri().toURL(); 
    URLConnection conn = url.openConnection();

    System.out.println("About to call getLastModified() on: " + url);
    long lastModified = conn.getLastModified();
    System.out.println("LastModified = " + lastModified);

    // try uncommenting to see if closing input stream changes behavior
    // try (var in = conn.getInputStream()) { /* no-op */ }

    System.out.println("Sleeping 60s. Try to delete/rename the file now.");
    Thread.sleep(60000);
    System.out.println("Done.");
}

} 