FIleinputStream字节输入
package File.io;import java.io.*;public class io1 {public static void main(String[] args) throws IOException {// InputStream is = new FileInputStream(new File("C:\\Users\\SUI\\Desktop\\Java1\\one\\src\\kaishi"));//简化InputStream is = new FileInputStream("C:\\Users\\SUI\\Desktop\\Java1\\one\\src\\kaishi");//开始读取文件的字节数据 read如果没有返回-1int a1 = is.read();System.out.println((char)a1);int a2 = is.read();System.out.println(a2);//使用循环int a;while ((a=is.read())!=-1){System.out.println((char)a);//读取数据功能差//汉字出现代码//使用必须关闭}is.close();}}
package File.io;import java.io.FileInputStream;
import java.io.FileNotFoundException;
import java.io.IOException;
import java.io.InputStream;public class io2 {public static void main(String[] args) throws IOException {InputStream is=new FileInputStream("C:\\Users\\SUI\\Desktop\\Java1\\one\\src\\kaishi");byte[] b = new byte[3];int a = is.read(b);String c=new String(b);System.out.println(c);System.out.println("读取的字节数量:"+a);//读取多少,倒出多少int a1=is.read(b);String c1=new String(b,0,a1);System.out.println(c1);System.out.println("读取的字节数量:"+a1);int a2=is.read(b);System.out.println(a2);//-1
//使用循环byte[] b=new byte[3];int len;while ((len=is.read(b))!=-1){String r=new String(b,0,len);System.out.println(r);}is.close();}
}
fwf
读取的字节数量:3
44
读取的字节数量:2
-1
一次性读取字节
输入流