java 输入输出流 一个类中只能使用一次吗? 流关闭后 就不能再打开吗?
publicclassInputUserInformation{/*从键盘输入,返回一个字符串*/publicStringinputName(){intcount;byt...
public class InputUserInformation { /*从键盘输入,返回一个字符串*/ public String inputName () { int count; byte[] b = new byte[256]; String str = ""; DataInputStream din = new DataInputStream(System.in); BufferedInputStream in = new BufferedInputStream(din); try { count = in.read(b); str = new String(b,0,count); } catch (IOException e) { e.printStackTrace(); System.out.print("发送I/O错误!"); } finally { try { din.close(); in.close(); } catch (IOException e) { e.printStackTrace(); } } return str; } public String inputPassword () { int count; byte[] b = new byte[256]; String str = ""; DataInputStream din = new DataInputStream(System.in); BufferedInputStream in = new BufferedInputStream(din); try { count = in.read(b); str = new String(b,0,count); } catch (IOException e) { e.printStackTrace(); System.out.print("发送I/O错误!"); } finally { try { din.close(); in.close(); } catch (IOException e) { e.printStackTrace(); } } return str; } }
展开
1个回答
推荐律师服务:
若未解决您的问题,请您详细描述您的问题,通过百度律临进行免费专业咨询
广告 您可能关注的内容 |