集册 Java实例教程 从流中获取字节

从流中获取字节

欢马劈雪     最近更新时间:2020-01-02 10:19:05

394
从流中获取字节
/* 
 来自 
*N o w  J a v a  .   c o m*/

/*******************************************************************************

 * Copyright (c) 2009 IBM Corporation and others.

 * All rights reserved. This program and the accompanying materials

 * are made available under the terms of the Eclipse Public License v1.0

 * which accompanies this distribution, and is available at

 * http://www.eclipse.org/legal/epl-v10.html

 *

 * Contributors:

 *     Matthew Hatem, IBM Corporation - initial API and implementation

 *     Boris Bokowski, IBM Corporation - initial API and implementation

 *******************************************************************************/

//package com.nowjava;

import java.io.ByteArrayOutputStream;


import java.io.IOException;

import java.io.InputStream;


public class Main {

    public static byte[] getBytesFromStream(InputStream is)

            throws IOException {

        int BUFFER_SIZE = 8192;

        byte[] buffer = new byte[BUFFER_SIZE];

        ByteArrayOutputStream os = new ByteArrayOutputStream();

        
展开阅读全文