首页 > 编程 > Java > 正文

Java基于IO流读取文件的方法

2019-11-26 14:54:50
字体:
来源:转载
供稿:网友

本文实例讲述了Java基于IO流读取文件的方法。分享给大家供大家参考,具体如下:

public static void readFile(){String pathString = TEST.class.getResource("/simu").getFile();try {  pathString = URLDecoder.decode(pathString, "utf-8");} catch (UnsupportedEncodingException e1) {  e1.printStackTrace();}System.out.println(pathString);File file = new File(pathString,"test.txt");InputStream is = null;try {  is = new FileInputStream(file);} catch (Exception e) {  e.printStackTrace();}BufferedReader br = new BufferedReader(new InputStreamReader(is));StringBuffer sb = new StringBuffer("");String b = "";try {  while((b=br.readLine())!=null){    sb.append(b).append("/n");  }} catch (Exception e) {  e.printStackTrace();}String bb = sb.toString();System.out.println(bb);}

希望本文所述对大家Java程序设计有所帮助。

发表评论 共有条评论
用户名: 密码:
验证码: 匿名发表