InputStream常用方法
public static void main(String[] args) {
String file = "123.txt";
try(var fos = new FileOutputStream(file);var fis = new
FileInputStream(file)){
fos.write("hello123".getBytes());
byte[] buf = new byte[10];
int len = fis.read(buf,2,3);
//len = 3
System.out.println(len);
//[0, 0, 104, 101, 108, 0, 0, 0, 0, 0]
System.out.println(Arrays.toString(buf));
//108
System.out.println(fis.read());
} catch (FileNotFoundException e) {
throw new RuntimeException(e);
} catch (IOException e) {
throw new RuntimeException(e);
}
}
OutputStream输出流( 实现程序数据到磁盘文件,写文件 ) OutputStream是以字节为单位的输出流的超类,提供了write()函数从输出流中读取字节数据。