MalformedURLException:未知协议:c ...如何处理? [英] MalformedURLException: unknown protocol: c... How to handle it ?
问题描述
我想读取一个位于我的文档目录中的文件
但是编译器会引发异常.说我指定的文件的路径有问题
这是我的代码的一部分
I want to read a file which located in my document directory
but the compiler throws an exception. says that there is a problem in the path of the file I specified
this is a segment of my code
String path = filePath;
DocumentBuilderFactory documentBuilderFactory = DocumentBuilderFactory.newInstance();
DocumentBuilder builder = documentBuilderFactory.newDocumentBuilder();
System.out.println(path);
document = builder.parse(path);
这是抛出的异常:
MalformedURLException:未知协议:c
我知道它说路径格式有问题.但我打印出来,看起来不错
这是我要读取的文件的路径
C:\ Documents and Settings \ AlOne \ My Documents \ SRS项目\ HR.xml
plz帮助我免于搜索; O
and this is the exception thrown:
MalformedURLException: unknown protocol: c
I knew it says there is problem in the path format. but I print it and it looks RIGHT
this is the path of the file I want to read
C:\Documents and Settings\AlOne\My Documents\SRS projects\HR.xml
plz Help Im tired from searching ;O
推荐答案
第一个链接(大约189000个)这里 [ ^ ]说
The first (of about 189000) link here[^] says
Thrown to indicate that a malformed URL has occurred. Either no legal protocol could be found in a specification string or the string could not be parsed.
您的消息然后显示未知协议".您是否在文件名前面加上了"file:///"?
我建议您阅读URL的格式.
如果您厌倦了搜索,也许我建议您在错误的地方寻找.
彼得
Your message then says "unknown protocol". Did you put "file:///" in front of the file name?
I suggest you read up on the format of URLs.
If you''re tired of searching, might I suggest that you are looking in the wrong places.
Peter
这篇关于MalformedURLException:未知协议:c ...如何处理?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!