IO流是为了从内存中读写硬盘的数据
写数据
创 FileOutputStream f=new FileOutputStream(“文件路径”) 当路径终点无此文件时 创建此文件
路径终点有文件时 覆盖此文件
FileOutputStream f=new FileOutputStream(“文件路径”,ture) 当路径终点有文件时 续写此文件
FileOutputStream f=new FileOutputStream(“路径文件”)
写 f.write(int a) 写入单个字节所对应的数字
f.write(byte[] arr) 把数组里的数字写出
f.write(arr,数组开始索引,要写入经过的索引)
换行\r\n
关 f.close
读数据
创 FileInputStream f=new FileInputStream(“文件路径”) 当路径终点无此文件时 报错
FileInputStream f=new FileInputStream("路径文件")
读 f.read() 读出单个字符所对应的数字 一次能读1个字节 汉字精度丢失
f.read(byte[] arr) 把文件的字符对应数字读取到数组中去 返回的结果为读到数组的数字个数
关 f.close
字符串转字节数组:”字符串”.getBytes()
字节数组转字符串: new String(byte[] arr)
字节数组的一部分转为字符串:new String(byte[] arr ,开始索引,经过的索引个数)
