public class FileUtils {

        private static final String ENCODING = "UTF-8";//编码方式

        /**
* 获取文件的行
*
* @param fileName
* 文件名称
* @return List<String>
*/
public static String getContentByLine(String fileName) {
StringBuffer lines = new StringBuffer();
InputStreamReader read = null;
BufferedReader bufferedReader = null;
try {
String configPath = FileUtils.class.getClassLoader().getResource(fileName).getPath();
configPath = configPath.replaceAll("%20", " ");// 处理文件路径中空格问题
File file = new File(configPath);
if (file.isFile() && file.exists()) { // 判断文件是否存在
read = new InputStreamReader(new FileInputStream(file), ENCODING);
bufferedReader = new BufferedReader(read);
String lineTxt = null;
while ((lineTxt = bufferedReader.readLine()) != null) {
if (lineTxt == null || lineTxt.length() == 0) {
continue;
}
lines.append(lineTxt);
}
}
} catch (Exception e) {
e.printStackTrace();
} finally {
try {
if (read != null) {
read.close();
}
} catch (IOException e) {
e.printStackTrace();
} finally {
if (bufferedReader != null) {
try {
bufferedReader.close();
} catch (IOException e) {
e.printStackTrace();
}
}
}
}
return lines.toString();
}
}

最新文章

  1. C#-WinForm-用户控件如何获取父级窗体
  2. DBCP连接池使用问题
  3. 【转】SQL 操作类
  4. 实现多项式的JAVA类
  5. onRetainNonConfigurationInstance和getLastNonConfigurationInstance
  6. ASP.NET中默认的一级目录
  7. 超级密码(bfs)
  8. Maven中有三大模块
  9. 优雅的使用Chrome调试Node程序
  10. 1、opencv-2.4.7.2的安装和vs2010的配置
  11. 1分钟解决VS每次运行都显示“正在还原nuget程序包”问题
  12. 极速搭建RTMP直播流服务器+webapp (vue) 简单实现直播效果
  13. [Python数据挖掘]第5章、挖掘建模(下)
  14. MySQL 并发测试中,线程数和数据库连接池的实验
  15. OGG文件获取创建日期
  16. 域名映射ip
  17. ThinkPHP问题收集:模板中使用U方法时无法嵌套大括号,For标签,插入数据,新增的表字段缓存问题
  18. javascript中创建对象的几种不同方法
  19. JavaWeb基础—JSP自定义标签入门
  20. jQuery的表单选择器

热门文章

  1. 【Linux-Redhat】新手需要知道的Linux命令
  2. Unique Morse Code Words
  3. 案例一(haproxy+keepalived高可用负载均衡系统)【转】
  4. 题解-AtCoder-agc003F Fraction of Fractal(非矩阵快速幂解法)
  5. 使用sudo而无需输入密码的设置
  6. 函数--&gt;指定函数---&gt;默认函数---&gt;动态函数--&gt; 动态参数实现字符串格式化--&gt;lambda表达式,简单函数的表示
  7. LabVIEW中下拉列表和枚举的区别(两点)
  8. signal &amp; slot
  9. 软件包.deb的安装及卸载------dpkg
  10. 用Python优雅的处理日志