public static String readFile(File file) { String line = null; try { InputStreamReader read = new InputStreamReader(new FileInputStream(file), "UTF-8"); BufferedReader reader = new BufferedReader(read); StringBuffer buf = new StringBuffer(); while ((line = reader.readLine()) != null) { buf.append(line + "\n"); } reader.close(); return buf.toString(); } catch (FileNotFoundException ex) { System.out.println("没有找到文件:" + file.getAbsolutePath()); } catch (Exception ex) { System.out.println(line); throw new RuntimeException(ex); }
java读取文件方法
最新推荐文章于 2024-04-15 05:12:44 发布