Java BufferedReader Read readFile(List fieldNames, String filename)

Here you can find the source of readFile(List fieldNames, String filename)

Description

read File

License

Apache License

Declaration

public static List<Map<String, String>> readFile(List<String> fieldNames, String filename) throws IOException 

Method Source Code


//package com.java2s;
//License from project: Apache License 

import java.io.BufferedReader;

import java.io.FileReader;

import java.io.IOException;
import java.util.ArrayList;
import java.util.HashMap;
import java.util.List;
import java.util.Map;

public class Main {
    public static List<Map<String, String>> readFile(List<String> fieldNames, String filename) throws IOException {
        List<Map<String, String>> rows = new ArrayList<Map<String, String>>();

        FileReader fr = new FileReader(filename);
        BufferedReader br = new BufferedReader(fr);
        br.lines().forEach(values -> {
            String[] vs = values.split(" ");
            Map<String, String> row = new HashMap<String, String>();
            for (int i = 0; i < fieldNames.size(); i++) {
                row.put(fieldNames.get(i), vs[i]);
            }/*from  w  w  w  .  ja v  a 2s  . co  m*/
            rows.add(row);
        });
        br.close();
        fr.close();
        return rows;
    }
}

Related

  1. readFile(final String fileName)
  2. readFile(final String filePath)
  3. readFile(final String name)
  4. readFile(final String path)
  5. readFile(final String pFile)
  6. readFile(Reader reader)
  7. readFile(String absoluteFilePath)
  8. readFile(String aFileName)
  9. readFile(String directory)