- import java.util.*;
- import java.lang.*;
- import java.io.*;
- public class Main
- {
- public static void main(String[] aegs)throws IOException
- {
- Scanner cin = new Scanner(System.in);
- TreeSet<String> TS = new TreeSet<String>();
- FileReader fr = new FileReader("H:\\JAVA\\java3\\18\\11.txt");
-
- BufferedReader Br = new BufferedReader(fr);
- String s = null;
- int count = 0, sum, t;
- while((s=Br.readLine())!=null)
- {
-
- TS.add(s);
- }
- while(cin.hasNext())
- {
- s = cin.next();
- s = s.toLowerCase();
- TS.add(s);
- }
- FileWriter fw1 = new FileWriter("H:\\JAVA\\java3\\18\\11.txt");
- FileWriter fw2 = new FileWriter("H:\\JAVA\\java3\\18\\12.txt");
- BufferedWriter Bw1 = new BufferedWriter(fw1);
-
- Iterator It = TS.iterator();
- sum = TS.size();
- String[] Danci = new String[sum];
- boolean[] Flag = new boolean[sum];
- while(It.hasNext())//把所有的单词保存到指定文件之中
- {
- s = It.next().toString();
- Danci[count++]=s;
- Bw1.write(s);
- Bw1.newLine();
- Bw1.flush();
- }
- BufferedWriter Bw2 = new BufferedWriter(fw2);
- for(int i=2;;i++)
- {
- t = (int)(Math.random()* i+count/2)%sum;
- if(Flag[t]==false)
- {
- count--;
- Flag[t]=true;
- Bw2.write(Danci[t]);
- Bw2.newLine();
- Bw2.flush();
- System.out.println(Danci[t]);
- }
- if(count==0)break;
- }
- fr.close();
- Br.close();
- Bw1.close();
- Bw2.close();
- System.out.println("over");
-
- }
- }
复制代码 我说一下注意事项啊....否则错了我不保证啊...
一定要保证你的连个文件存在,一定要啊...否则会异常的,
H:\\JAVA\\java3\\18\\11.txt//用来保存单词的的txt文本
H:\\JAVA\\java3\\18\\12.txt//用来保存无序单词的txt文本
能够添加,但是不能删除...
能够去重 YES Yes yes 只能存储一个...
望满足要求..
over是用来标记程序运行结束...
|