原来以为很难,其实很简单,所以写个博客作为知识点总结。
/**
* This file created at 2012-6-14.
*
* Copyright (c) 2002-2012 Bingosoft, Inc. All rights reserved.
*/
package com.bingosoft.test;
import java.io.IOException;
import java.net.MalformedURLException;
/**
* <code>{@link Test}</code>
*
* TODO : document me
*
* @author HJP
*/
public class Test {
public static void main(String[] args) {
String imageFilePath = "http://127.0.0.1:8080/pdfTest/servlet/barCode?msg=201200148-003&mw=0.4mm&type=code128&hrpattern=001-&filename=temp.jpg";
try {
// 实例化url
java.net.URL url = new java.net.URL(imageFilePath);
try {
// 载入图片到输入流
java.io.BufferedInputStream bis = new java.io.BufferedInputStream(
url.openStream());
byte[] buf = new byte[bis.available()];
bis.close();
System.out.println("远程文件流" + buf);
} catch (IOException e) {
e.printStackTrace();
}
} catch (MalformedURLException e) {
e.printStackTrace();
}
}
}