public String readTxtFile(String filePath) { StringBuffer appInfolistInput = new StringBuffer(); try { String encoding = "UTF8"; File file = new File(filePath); if (file.isFile() && file.exists()) { InputStreamReader read = new InputStreamReader( new FileInputStream(file), encoding); BufferedReader bufferedReader = new BufferedReader(read); String lineTxt = null; while ((lineTxt = bufferedReader.readLine()) != null) { appInfolistInput.append(lineTxt); } read.close(); bufferedReader.close(); } else { System.out.println("找不到指定的文件"); } } catch (Exception e) { System.out.println("读取文件内容出错"); e.printStackTrace(); } return appInfolistInput.toString(); }
时间: 2024-11-05 03:06:26