Java如何把字符串转化为输入流 博客分类: 字符集 java
程序员文章站
2024-03-19 15:24:16
...
try{
InputStream myIn=new ByteArrayInputStream(txt.getBytes());
//将System.in转化为面向字符的流
InputStreamReader ir = new InputStreamReader(myIn);
in = new BufferedReader(ir);//为输入流提供缓冲区
while ((s = in.readLine()) != "bye")
System.out.println("Read: " + s);
}
catch(IOException e)
{System.out.println("Error! ");}
}
InputStream myIn=new ByteArrayInputStream(txt.getBytes());
//将System.in转化为面向字符的流
InputStreamReader ir = new InputStreamReader(myIn);
in = new BufferedReader(ir);//为输入流提供缓冲区
while ((s = in.readLine()) != "bye")
System.out.println("Read: " + s);
}
catch(IOException e)
{System.out.println("Error! ");}
}