io

作者: Vijay_ | 来源:发表于2018-03-02 09:39 被阅读0次

BufferedInputString(有缓存的FileInputStream)加速 缓存

String url = "/Users/adamvijay/IdeaProjects/SSM/src/main/resources/aa.properties";
File file = new File(url);
BufferedInputStream inputStream = new BufferedInputStream(new FileInputStream(file));
byte[] caches = new byte[1024];//1kb
int i = 0;
StringBuffer stringBuffer = new StringBuffer();
while((i=inputStream.read(caches))!=-1){
//            i是获取本次读取了多少数据到缓存中,为的是避免长度不能整除的情况下最后一次读取不能把caches缓存区读满
//            如果缓存数组没有读满就把整个数组构建字符串会,那空位的数组角标就会形成乱码字符串
    stringBuffer.append(new String(caches,0,i,"UTF-8"));
}
sout(stringBuffer.toString());

相关文章

网友评论

      本文标题:io

      本文链接:https://www.haomeiwen.com/subject/xdboxftx.html