Java读取含有数字的txt文件

Java读取含有空格以及换行的的完全数字txt文件

package 读取文件;

import java.io.BufferedReader;
import java.io.FileReader;
import java.io.IOException;

public class Test {	
		public static void main(String[] args) throws IOException {		
			BufferedReader bf=new BufferedReader(new FileReader("F:\\data.txt"));
			String textLine;
			String str = "2";
			while((textLine=bf.readLine())!=null){
				str+="	"+textLine;
			}
			String[] numbers=str.split("	");
			double []number=new double[numbers.length]; 
			for (int i = 1; i < numbers.length; i++) {
				number[i]=Double.parseDouble(numbers[i]);
				System.out.println(number[i]);
			}
			bf.close();
		}
}

你可能感兴趣的:(Java)