标签:title ast led arrays sys 多个 跳转 stat exception
import java.io.FileInputStream; import java.io.IOException; import java.util.Arrays; //一次读取多个字节 public class Demo02InPutStream { public static void main(String[] args) throws IOException { FileInputStream fis=new FileInputStream("F:\\basic\\untitled13\\src\\it\\cast\\day15\\demo01\\1.txt"); /* byte[] bytes=new byte[2];//起到缓冲作用,存储每次读取到的多个字节 int len=fis.read(bytes); System.out.println(Arrays.toString(bytes)); System.out.println(new String(bytes));*/ byte[] bytes1=new byte[1024]; int len=0; while ((len=fis.read(bytes1))!=-1){ System.out.println(new String(bytes1,0,len));//读取有效的几个 } fis.close(); } }
import java.io.FileInputStream; import java.io.IOException; public class Demo01InPutStream { public static void main(String[] args) throws IOException { FileInputStream fis=new FileInputStream("F:\\basic\\untitled13\\src\\it\\cast\\day15\\demo01\\2.txt"); int read=0; while ((read=fis.read())!=-1) {//read运行一次跳转一次 System.out.print((char) read); } fis.close(); } }
标签:title ast led arrays sys 多个 跳转 stat exception
原文地址:https://www.cnblogs.com/cy2268540857/p/13773900.html