import java.io.*;
public class TestByteArray {
public static void main(String[] args) {
byte[] buffer = "asadhjkk".getBytes();
ByteArrayInputStream in = new ByteArrayInputStream(buffer);
ByteArrayOutputStream out = new ByteArrayOutputStream();
transform(in,out);
transform(System.in,System.out);
}
public static void transform(InputStream in,OutputStream out)
{
int ch1 = 0;
int ch2 = 0;
try{
while((ch1 = in.read())!=-1)
{
ch2 = Character.toUpperCase(ch1);
out.write(ch2);
}
if((out.toString()).equals("bye"))
System.in.close();
System.out.println(out.toString());
}
catch(Exception ex){}
}
}
怎样才能在输入“bye”之后结束程序了,我那段代码好像不行。
|
|