public static void crypt(InputStream in, OutputStream out)throws Exception
{
byte[] inBytes = new byte[8];
int inLength = 0;
boolean more = true;
while (more)
{
inLength = in.read(inBytes);
if (inLength == 8)
{
//...
}
else
more = false;
}
}如题,我要用它来更新一个ProgressBar
{
byte[] inBytes = new byte[8];
int inLength = 0;
boolean more = true;
while (more)
{
inLength = in.read(inBytes);
if (inLength == 8)
{
//...
}
else
more = false;
}
}如题,我要用它来更新一个ProgressBar
int i= 0;//循环次数
while (more) {
i++;
System.out.println("i=" + i);
inLength = in.read(inBytes);
if (inLength == 8)
{
//...
}
else
more = false;
}}
int count = is.available()/8+1;//....
读文件不是这样读的....byte[] buffer = new byte[1024];
int readSize = 0;while((readSize = is.read(buffer) != -1){
...
}用Stream读文件的话,read返回当前读取到缓冲区的字符数
如果剩余字符大于缓冲区,返回的是缓冲区大小
如果剩余字符小于缓冲区,返回的是读取到的字符数
如果文件已经读完,返回 -1直接判断是不是返回 -1 就行了