从键盘中读取字符流 自定义异常
public class Demo{public static void main(String[] args) {Demo d = new Demo();d.in();}public void in(){InputStreamReader in = null;in = new InputStreamReader(System.in);char[] c = new char[10];int i = -1;try {if ((i = in.read(c)) < 10){//输出输入的字符串System.out.println(new String(c,0,i));}else{throw new MyStringException();}} catch (MyStringException e){System.out.println("==============================");System.out.println("请重新输入:");in();} catch (IOException e) {e.printStackTrace();} finally {try {in.close();} catch (IOException e) {e.printStackTrace();}}}
}class MyStringException extends Exception{public MyStringException(){System.out.println("错误:长度不足!");}
}
从键盘中读取字符流 自定义异常相关推荐
- java 从键盘中读取字符流 自定义异常
public class Demo{public static void main(String[] args) {Demo d = new Demo();d.in();}public void in ...
- Java中使用字符流读取UTF-8和写出txt文件 乱码 问题
乱码问题一直都是非常难受的问题,本文解决Java中使用字符流读取UTF-8和写出txt文件 乱码 话不多说,直接上图 输出结果: 使用代码: 解决:
- 文件_ _android从资源文件中读取文件流并显示的方法
======== 1 android从资源文件中读取文件流并显示的方法. 在android中,假如有的文本文件,比如TXT放在raw下,要直接读取出来,放到屏幕中显示,可以这样: private ...
- c#读取指定字符后的字符_在C#中读取字符的不同方法
c#读取指定字符后的字符 As we know that, Console.ReadLine() is used for input in C#, it actually reads a string ...
- python 服务端读取字符流和字节流(udp)
pyhon udp服务器读取字符流 程序如下: from socket import * import time import oshost = '' port =8899 bufsize = 102 ...
- Java中Properties+字符流 读写文本文件
String getProperty(String key) :通过键获取值 Object setProperty(String key, String value) :设置属性键值对 void lo ...
- 关于java中的字符流的一个使用例子
使用字符流的方式进行文件HelloWorld.java的读取并打印至控制台. package test;import java.io.BufferedInputStream; import java. ...
- VC++从txt文本中读取字符和数字
例子: #include<string.h> #include<iostream> #include<stdio.h> using namespace std; i ...
- Java IO: 字符流的Piped和CharArray
转载自 Java IO: 字符流的Piped和CharArray 作者: Jakob Jenkov 译者: 李璟(jlee381344197@gmail.com) 本章节将简要介绍管道与字符数组相 ...
最新文章
- 2008_10_28_星期二
- Android最佳性能实践(二)——分析内存的使用情况
- 如何让PHP运行更高效
- QT的QOperatingSystemVersion类的使用
- 初识消息队列/RabbitMQ详解
- 输入某年某月某日,Java判断这一天是这一年的第几天?
- C# typeof()实例详解
- Ros安装过程及sudo rosdep init失败解决方法
- wordpress上传图片按时间重命名
- LintCode #4. 丑数 II
- ISO27000信息安全管理体系
- vnr懒人版教程_【转载】Galgame老司机实用工具:VNR使用教程
- ps文件怎么导出html文件,PS存储到网页格式的最佳方式
- 应用在AVR上的拼音输入法
- C语言分号总是报错,问什么C程序里总是提示缺少分号;,而明明有分号?
- win10系统开启局域网共享
- C++ day22 继承(二)基类指针数组通过虚方法实现智能的多态
- Linux 文本对比 diff
- 【python-docx 06】理解word样式
- star邀请码卡密获取以及使用方法