读取class根下的文件

来源:互联网 发布:profili2.3软件下载 编辑:程序博客网 时间:2024/06/18 15:26
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();}

原创粉丝点击