java代码获取txt文件内容并按行放入list中【转】

 java 代码  获取文件内容并存入list中

/**
	 * 获取txt文件内容并按行放入list中
	 */
	public static List<String> getFileContext(String path) throws Exception {
		FileReader fileReader =new FileReader(path);
        BufferedReader bufferedReader =new BufferedReader(fileReader);
        List<String> list =new ArrayList<String>();
        String str=null;
        while((str=bufferedReader.readLine())!=null) {
        	if(str.trim().length()>2) {
        		list.add(str);
        	}
        }
		return list;
    }

猜你喜欢

转载自blog.csdn.net/dr_HuangChao/article/details/82589470