[英]Why do we have to convert InputStream to ByteArrayOutputStream?
[英]Why do we compare the return value of InputStream read() method with -1?
在此while语句中while ((c = in.read()) != -1)
-1是什么意思? 有关更多详细信息,请参见以下程序:
import java.*;
public class CopyFile
{
public static void main(String args[]) throws IOException
{
FileInputStream in = null;
FileOutputStream out = null;
try {
in = new FileInputStream("input.txt ");
out = new FileOutputStream("output.txt");
int c;
while ((c = in.read()) != -1)
{
out.write(c);
}
}
finally
{
if (in != null) {
in.close();
}
if (out != null) {
out.close();
}
}
}
}
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.