Convert String to Uri

2.1K    Asked by MintaAnkney in Python , Asked on Jul 14, 2021

How is it possible to convert a String to a URL in Java (Android)? How do I convert a file to URI?

Answered by Jonathan Skinner

 'URL' is a class. Use 'new' to convert string to uri and create a new instance of the class URL and pass the string myUrl as a parameter to the constructor.

String  yUrl = "https://www.janbasktraining.com/";

URL myURL = new URL(myUrl);

Steps to convert local file path to URL & URI in java (example)

Absolute file: D:CodeLocalFilePath.txt.

URL of given file is: file:/D:/Code/LocalFilePath.txt.

URI of given file is: file:/D:/Code/LocalFilePath.txt.



Your Answer

Interviews

Parent Categories