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 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 new File(URI);


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]

^ <