I've little knowledge of Java. I need to construct a string representation of an URI from FilePath(String)
on windows. Sometimes the inputFilePath
I get is: file:/C:/a.txt
and sometimes it is: C:/a.txt
. Right now, what I'm doing is:
new File(inputFilePath).toURI().toURL().toExternalForm()
The above works fine for paths, which are not prefixed with file:/
, but for paths prefixed with file:/
, the .toURI
method is converting it to a invalid URI, by appending value of current dir, and hence the path becomes invalid.
Please help me out by suggesting a correct way to get the proper URI for both kind of paths.
See Question&Answers more detail:
os 与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…