public static void main(String[] args) {
rFile(this.getClass().getResource("/").getPath()+"/json_free.txt");
}
public static String rFile(String path) {
long begin = System.currentTimeMillis();
FileInputStream inSTr = null;
BufferedInputStream Buff = null;
StringBuffer sb = new StringBuffer();
try {
inSTr = new FileInputStream(new File(path));
Buff = new BufferedInputStream(inSTr);
byte c[] = new byte[1024 * 48];
int n = 0;
while ((n = Buff.read(c)) != -1) {
String temp = new String(c, 0, n);
sb.append(temp);
}
long end = System.currentTimeMillis();
System.out.println("BufferedInputStream执行耗时:" + (end - begin) + " 豪秒");
} catch (FileNotFoundException e) {
e.printStackTrace();
} catch (IOException e) {
e.printStackTrace();
} finally {
try {
Buff.close();
inSTr.close();
} catch (Exception e) {
e.printStackTrace();
}
}
return sb.toString();
}
读取class根下的文件
最新推荐文章于 2022-07-19 13:05:19 发布