Java URL:未知协议“C” [英] Java URL: Unknown Protocol "C"
问题描述
我知道在这个问题上有类似的问题(比如 我正在使用 iText 库从Swing应用程序中生成PDF。 iText的 当我把这个 是否存在任何黑客/绕行行为,或者 是否在某处放置此JPG,并且 请注意: 谢谢您需要将路径转到image.jpg文件到 file:// URL ,如下所示: 否则它会将C解释为URL协议。 I know there are similar questions to this one on SO (like this one), however, after reading through the list of "Questions with similar titles", I still feel strongly that this is unique. I am working with the iText library to generate PDFs from inside a Swing application. iText's When I set this Is there any hack/circumvention to this, or do I have to host this JPG somewhere and have the Please note: The Thanks in advance! You need to turn the path to the image.jpg file into a file:// URL, like this: Otherwise it interprets the C as the URL protocol. 这篇关于Java URL:未知协议“C”的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
Jpeg
类需要一个 URL
在其构造函数中找到要添加到PDF文件的图像/ jpg。
URL
设置为我的JPG文件的绝对文件路径时,我得到了一个 MalformedURLException
声明未知协议:c (c是我的本地磁盘上的 C:\
驱动器)。 b
$ b URL
通过网络找到它?这是失败的代码:
try {
String imageUrl =C:\Users\MyUser \image.jpg;
Jpeg image = new Jpeg(new URL(imageUrl));
} catch(Exception exc){
System.out.println(exc.getMessage());
URL
不会正确地转义字符串(因此\会转换为\ \等)。
String imageUrl =file:/// C:/Users/MyUser/image.jpg;
Jpeg
class requires a URL
in its constructor to locate an image/jpg that you want to add to the PDF file.URL
to the absolute file path of my JPG file, I get a MalformedURLException
claiming unknown protocol: c ("c" being the C:\
drive on my local disk).URL
find it over the net? Here is the code that is failing:try {
String imageUrl = "C:\Users\MyUser\image.jpg";
Jpeg image = new Jpeg(new URL(imageUrl));
} catch(Exception exc) {
System.out.println(exc.getMessage());
}
URL
does properly escape the string (thus "\" are converted to "\ \", etc.).String imageUrl = "file:///C:/Users/MyUser/image.jpg";