将txt文件读取并且以空格为界输出到控制台
package home;
import java.io.*;
public class ReadAfile {
/**
* @param args
*/
public static void main(String[] args) {
// TODO Auto-generated method stub
try{
File myFile=new File("D://stu.txt");
FileReader fileReader =new FileReader(myFile);
BufferedReader reader=new BufferedReader(fileReader);
String line=null;
while((line=reader.readLine())!=null){
String []result=line.split(" ");
for (String token:result){
System.out.println(token);
}
}
reader.close();
}catch(Exception ex){
ex.printStackTrace();
}
}
}