简体   繁体   中英

How to check directory exist in remote server using java, when i check i got URI is not absolute

This is my sample code below,

  URI uri=new URI("/192.168.0.135/user-directories/test01/");
     File f=new File(uri);
     System.out.println(""+f.exists());

Output is:

URI is not absolute
java.lang.IllegalArgumentException: URI is not absolute
    at java.io.File.<init>(File.java:361)

How to check remote directory exist using File?

If your communication is with a FTP Server I this link will help you: http://www.codejava.net/java-se/networking/ftp/determine-if-a-directory-or-file-exists-on-ftp-server

PS: For some reason the website is not allowing me to add a comment so posted in the answer section. Not sure if this answers your question.

Your URI is not absolute. See RFC 3986 Section 4.3. Absolute URI

Also see https://docs.oracle.com/javase/8/docs/api/java/net/URI.html

An absolute URI specifies a scheme; a URI that is not absolute is said to be relative.

You need to provide a scheme like http , ftp or other.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM