1、建立C:/Users/yangwei/workspace/filetest.txt 文件
1 1 1
2 1 3
3 20 45
4 24 56
5 300.235 230.256
2、代码
import java.io.BufferedReader;
import java.io.FileInputStream;
import java.io.IOException;
import java.io.InputStreamReader;
import java.util.ArrayList;
public class Fileprocess {
//static Vector<Point> li=new Vector<Point>();
static ArrayList<double[]> dataSet = new ArrayList<double[]>();
public Fileprocess() {
// TODO Auto-generated constructor stub
}
//读取数据
public static final void readF1() throws IOException {
String filePath="C:/Users/yangwei/workspace/filetest.txt";
BufferedReader br = new BufferedReader(new InputStreamReader(
new FileInputStream(filePath)));
for (String line = br.readLine(); line != null; line = br.readLine()) {
if(line.length()==0||"".equals(line))continue;
String[] str=line.split(" ");
dataSet.add(new double[] { Double.valueOf(str[0]) , Double.valueOf(str[1]), Double.valueOf(str[2]) });
//System.out.println(line);
}
br.close();
}
public static void main(String[] args) throws IOException {
// TODO Auto-generated method stub
System.out.println("yangwei");
Fileprocess test1=new Fileprocess();
//读取数据
// readF1();
test1.readF1();
for (int i = 0; i < dataSet.size(); i++)
{
System.out.println("filedata:" + dataSet.get(i)[0] + "," + dataSet.get(i)[1] + ","+ dataSet.get(i)[2] + "}");
}
}
}