java2db

How to create a file from URI with File constructor



File having four constructors,In that one of the constructor taking URI as an argument.Use java.net.URI to get URI for the sepecified path.See the bellow example to create a File from URI with File constructor.

To create a file from URI with File constructor
Get URI by using getURI() method if path having any blank spaces like C:/user file/….
Pass the URI object to the FILE constructor.ie new File(URI);

Syntax:

File <FileObjectName> = new File(<URIobjectName>);

Example Code:

Execution Result:

Conclusion :

See the above result ,Tha path having  blank space is replace by %20.
If the path not having any blank spaces ,just pass the String path to URI constructor like
URI uri = new URI(“file:/C:/userfile/newFile.txt”).Here userfile having no blank space.




Related Posts :

No related posts found!

   [will not be published]



^ <