读入字符串,遇到某一字符结束读入

来源:互联网 发布:淘宝宝贝描述在哪里 编辑:程序博客网 时间:2024/05/20 23:55
/** * 读入字符串,遇到某一字符结束读入 * int.txt: 中国123美国abc日本;123 */import java.io.*;class Test{public static void main(String[] args) throws IOException{FileReader in = new FileReader("in.txt");int c;StringBuffer sb = new StringBuffer();c = in.read();while( (c != ';') && (c != -1) ){sb.append((char)c);c = in.read();}System.out.println(sb);in.close();}}

原创粉丝点击