其他分享
首页 > 其他分享> > 通过流按行读取txt文件

通过流按行读取txt文件

作者:互联网

/**
	 * 文件流读取并存List
	 * 2019-08-02
	 * @param FilePath 文件路径
	 * @param ecoding 文件编码集
	 * 
	 * @author bing
	 */
	public List<String> readTxt(String FilePath,String ecoding) {

		List<String> itemList = new ArrayList<String>();
		/* 读取数据 */
		try {
			TrcLog.log(LOG_FILE, "--开始读取文件");
			BufferedReader br = new BufferedReader(
					new InputStreamReader(new FileInputStream(new File(FilePath)), ecoding));
			String lineTxt = "";
			while ((lineTxt = br.readLine()) != null) {
				itemList.add(lineTxt);
			}
			br.close();
		} catch (Exception e) {
			TrcLog.log(LOG_FILE, "--文件读取错误");
			throw new BaseException("PCA1006", "文件读取错误");
		}
		
		return itemList;
	}

标签:文件,String,lineTxt,itemList,按行,new,txt,读取
来源: https://blog.csdn.net/qq_37427750/article/details/98751337