/** * 读取指定路径的文本 * * @param path * 文本路径 */ public static void readFileByPath(String path) { if (null == path) { return; } File file = new File(path); if (file.exists() && file.isFile()) { InputStreamReader reader = null; BufferedReader br = null; try { reader = new InputStreamReader(new FileInputStream(file), "gbk"); br = new BufferedReader(reader); String lineText = null; while ((lineText = br.readLine()) != null) { System.out.println(lineText); } } catch (Exception e) { e.printStackTrace(); System.out.println("文件读取错误"); } finally { // 关闭流 if (null != br) { try { br.close(); } catch (IOException e) { e.printStackTrace(); } } if (null != reader) { try { reader.close(); } catch (IOException e) { e.printStackTrace(); } } } } else { System.out.println("文件错误!"); } }