Tag Archives: : MalformedURLException: unknow protocol: f

JAVA Error: MalformedURLException: unknow protocol: f

Question:

Java use URL reading file interpretation error MalformedURLException

1. Malformedurlexception: unknown protocol: F is reported when using URL object to parse the file. It’s quite confusing. Check the URL class source code

It is found that the parameter prefix needs to be “Protocol”, because the parameter I transmitted is a file under a disk. Of course, the drive letter here is not a protocol, so I decided to add it in front

File:///, the whole becomes   file:/// F://test.txt

because   “file:///” Is a standard general document protocol

2. Here is a knowledge point, that is, the HTTP protocol we usually know. The general path is http://10.0.0.1:port/xxx/xxx ,

Why is the File Protocol   ///, The difference is that the file path has no host, that is, the host IP, so it is directly omitted here