无法确定地知道InputStream对象中的字节数。
下面的代码可以将文件放入byte[]。参照以下代码,从输入流中获取完整的byte[]也可以实现。 private static byte[] loadByteArray(
String fileName)
throws IOException
{
FileInputStream inFile = new FileInputStream(fileName);
ByteArrayOutputStream outByteArray =
new ByteArrayOutputStream();
int i = -1;
while ((i = inFile.read())!=-1)
outByteArray.write((byte)i);
byte[] byteArray = outByteArray.toByteArray();
inFile.close();
outByteArray.close();
return byteArray;
}

解决方案 »

  1.   

    import java.io.*;public class iioo {
    public static void main(String[] args){
    try{
    String s="english中文";
    InputStream input=new StringBufferInputStream(
    new String(s.getBytes(),"iso8859-1"));
    byte[] bt=new byte[input.available()];
    input.read(bt);
    System.out.println(new String(bt,"gb2312"));
    }
    catch(IOException e){
    e.printStackTrace();
    }
    }
    }
    我自己顶上,解决了。