JAVA 字符流读数据的两种方式 146
作者:互联网
import java.io.FileInputStream; import java.io.FileNotFoundException; import java.io.IOException; import java.io.InputStreamReader; public class InputStreamReaderDemo { public static void main(String[] args) throws IOException { InputStreamReader isr = new InputStreamReader(new FileInputStream("1.txt")); int ch; while ((ch=isr.read())!=-1){ System.out.println((char)ch); } System.out.println("====分割符号======"); //第二种 读一个字符素组 char[] chs = new char[1024]; int len; while ((len= isr.read(chs)) !=-1 ){ System.out.println(new String(chs,0,len)); } isr.close(); } }
标签:146,ch,java,isr,读数据,io,import,JAVA,new 来源: https://www.cnblogs.com/phpwyl/p/16079622.html