Java BufferedReader Read loadByUsingSplit(String filename)

Here you can find the source of loadByUsingSplit(String filename)

Description

load By Using Split

License

Open Source License

Declaration

protected static double[][] loadByUsingSplit(String filename)
            throws IOException 

Method Source Code

//package com.java2s;
/*-// w ww  .j a va  2 s  .  c  o  m
 * Copyright ? 2009 Diamond Light Source Ltd.
 *
 * This file is part of GDA.
 *
 * GDA is free software: you can redistribute it and/or modify it under the
 * terms of the GNU General Public License version 3 as published by the Free
 * Software Foundation.
 *
 * GDA is distributed in the hope that it will be useful, but WITHOUT ANY
 * WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS
 * FOR A PARTICULAR PURPOSE. See the GNU General Public License for more
 * details.
 *
 * You should have received a copy of the GNU General Public License along
 * with GDA. If not, see <http://www.gnu.org/licenses/>.
 */

import java.io.BufferedReader;
import java.io.FileInputStream;
import java.io.IOException;
import java.io.InputStreamReader;

import java.util.List;
import java.util.Vector;

public class Main {
    protected static double[][] loadByUsingSplit(String filename)
            throws IOException {
        BufferedReader br = new BufferedReader(new InputStreamReader(
                new FileInputStream(filename)));
        return getDataFromReaderUsingSplit(br);
    }

    protected static double[][] getDataFromReaderUsingSplit(BufferedReader r)
            throws IOException {
        try {
            List<double[]> data = new Vector<double[]>();
            String line = null;
            while ((line = r.readLine()) != null) {
                String[] tokens = line.split(" ");
                double[] values = new double[tokens.length];
                for (int i = 0; i < tokens.length; i++) {
                    values[i] = Double.parseDouble(tokens[i]);
                }
                data.add(values);
            }
            return data.toArray(new double[data.size()][]);
        } finally {
            try {
                r.close();
            } catch (IOException e) {
                // ignore
            }
        }
    }
}

Related

  1. loadAPIKey(InputStream in)
  2. loadAuthFile(String fileName)
  3. loadBase64Object(BufferedReader rdr, String type)
  4. loadBlackList(String blackListPath)
  5. loadBussinessGroupCompanies(String file_path)
  6. loadClob(File f, String enc)
  7. loadCommonMisspellingsFile(String commonMisspellingsFileLocation)
  8. loadConfFile(String filename, String key)
  9. loadConfig(File conf)