疯狂java


您现在的位置: 疯狂软件 >> 新闻资讯 >> 正文

java程序文本输入输出操作


 

   

  import java.util.*;

  import java.io.*;

  class txt

  {

  public static void main(String []args)throws Exception

  {

  String s1="撒旦 撒打算的 撒打算的";

  String s2="发疯似的发达 所发生的防守对方 撒旦发射点发";

  StringTokenizer pas1=new StringTokenizer(s1," ");

  StringTokenizer pas2=new StringTokenizer(s2);

  System.out.println("s1的单词数为:"+pas1.countTokens());

  System.out.println("s1中的单词为:");

  while(pas1.hasMoreTokens())

  {

  System.out.println(pas1.nextToken());

  }

  System.out.println("s2的单词数为:"+pas2.countTokens());

  System.out.println("s2中的单词为:");

  while(pas2.hasMoreTokens())

  {

  System.out.println(pas2.nextToken());

  }

  File f=new File("test.txt");

  if(!f.exists())

  {

  f.createNewFile();

  }

  FileReader fr=new FileReader(f);

  BufferedReader b=new BufferedReader(fr);

  String s="";

  while((s=b.readLine()) !=null )

  {

  StringTokenizer st=new StringTokenizer(s," ");

  System.out.println("学号:"+st.nextToken());

  System.out.println("姓名:"+st.nextToken());

  System.out.println("成绩:"+st.nextToken());

  }

  }

  }