一:字节流
二:字符流
原则:能直接字节流的可以字节流,然后字符流
使用场景:除非需要字符流,也就是需要字符保存然后查看,其它均可以字节流;所以保存密钥等内容可以字节流
字节流
读:
FileInputStream fis = new FileInputStream(new File(filePath+fileName));
BufferedInputStream bis = new BufferedInputStream(fis);
byte []buffer = new byte[bis.available()];
bis.read(buffer);
写
FileOutputStream fos = new FileOutputStream(new File(filePath+fileName));
BufferedOutputStream bos = new BufferedOutputStream(fos);
bos.write(fileContent.getBytes());