`
huangjinping
  • 浏览: 49035 次
  • 性别: Icon_minigender_2
  • 来自: 广州
社区版块
存档分类
最新评论

java读取远程文件的文件流

    博客分类:
  • Java
阅读更多

原来以为很难,其实很简单,所以写个博客作为知识点总结。

/**
 * 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();
		}
	}
}
 

 

 

 

分享到:
评论

相关推荐

Global site tag (gtag.js) - Google Analytics