从文件读取数据到Vector用数组返回

package util;


import java.io.BufferedReader;
import java.io.FileReader;
import java.util.Vector;


public class ReadFile {
	Vector<String> vec = new Vector<String>();
	public String[] readFile(String filename) {
		try {
			BufferedReader br = new BufferedReader(new FileReader(filename));
			String str = "";
			while ((str = br.readLine()) != null) {


				int a = str.indexOf("1");
				String newStr = str.substring(a);
				String[] arryStr = newStr.split(" ");
				for (int i = 0; i < arryStr.length; i++) {
					// System.out.println(arryStr[i]);
					vec.add(arryStr[i]);
				}
			}
		} catch (Exception e) {
			e.printStackTrace();
		}
		String[] result = new String[vec.size()];
		for (int i = 0; i < vec.size(); i++) {
			result[i] = vec.get(i);
		}
		return result;


	}
}


阅读更多
个人分类: Java技术
想对作者说点什么? 我来说一句

没有更多推荐了,返回首页

关闭
关闭
关闭