|
|
我用了Iterator但是在notepad却不能跳去下一行
出来是这样:
[Ben, Emelia, Linda, Orlando, Romeo, Ruth, Watson]
我要的是这样:
Ben
Emelia
linda
orlando
romeo
ruth
watson
import java.util.*;
import java.io.*;
public class StudentAcc
{
public static void main(String [] args){
TreeSet<String>currAccs = new TreeSet<String>();
TreeSet<String>oldAccs = new TreeSet<String>();
TreeSet<String>gradAccs = new TreeSet<String>();
TreeSet<String>newAccs = new TreeSet<String>();
try
{
readAccounts("currAccounts.txt",currAccs);
readAccounts("oldAccounts.txt",oldAccs);
gradAccs.addAll(oldAccs);
gradAccs.removeAll(currAccs);
newAccs.addAll(currAccs);
newAccs.removeAll(oldAccs);
}
catch(IOException ioe){
System.out.println("Cannot open file");
System.exit(1);
}
FileOutputStream out1;
PrintStream p1;
FileOutputStream out2;
PrintStream p2;
try
{
out1 = new FileOutputStream("gradAccounts.txt");
out2 = new FileOutputStream("newAccounts.txt");
p1 = new PrintStream(out1);
p2 = new PrintStream(out2);
p1.println(gradAccs);
p2.println(newAccs);
p1.close();
p2.close();
}
catch (Exception A)
{
System.out.println("Error writing to file");
}
System.out.println("Graduated Students");
System.out.println("-------------------");
Iterator iter = gradAccs.iterator();
while (iter.hasNext())
{
System.out.println(iter.next()+" ");
}
System.out.println();
System.out.println("New Students");
System.out.println("-------------------");
Iterator iter2 = newAccs.iterator();
while (iter2.hasNext())
{
System.out.println(iter2.next()+" ");
}
}
谁可以帮帮忙??????????????非常紧急 |
|