Java从文件读入数据并打印到显示器

import java.io.BufferedReader;
import java.io.File;
import java.io.FileReader;
import java.io.IOException;
import java.util.StringTokenizer;

public class test {
	public static void main(String[] args) throws IOException {
		File file = new File("nations.txt");
		BufferedReader in = new BufferedReader(new FileReader(file));
		String line = in.readLine();
		while(line != null) {
			StringTokenizer str = new StringTokenizer(line, ",");
			String nation = str.nextToken();
			String capital = str.nextToken();
			System.out.println(nation + "\t\t" + capital);
			line = in.readLine();
		}
		in.close();
	}
}


原文链接: http://blog.csdn.net/poechant/article/details/6958132

你可能感兴趣的:(Java从文件读入数据并打印到显示器)