为什么任务台无动作呢?各位大神

import java.io.*;
import java.util.*;
public class TextFileTest
{
public static void main(String[] args) throws IOException
{
Employee[] staff=new Employee[3];
staff[0]=new Employee("Carl Cracker",75000,1987,12,15);
staff[1]=new Employee("Harry Hacker",50000,1989,10,1);
staff[2]=new Employee("Tony Tester",40000,1990,3,15);

    try(Scanner in=new Scanner(new FileInputStream("F:\\JAVA\\123.txt"),"UTF-8"))
    {           
        PrintWriter out =new PrintWriter("F:\\JAVA\\123.txt");
        writeData(staff,out);
    }
    try(Scanner in=new Scanner(new FileInputStream("F:\\JAVA\\123.txt"),"UTF-8"))
    {
        Employee[] newStaff=readData(in);
        for(Employee e:newStaff)
            System.out.println(e);
    }       
}

private static void writeData(Employee[] employees,PrintWriter out) throws IOException
{
    out.println(employees.length);
    for(Employee e: employees)
        writeEmployee(out,e);
}
private static Employee[] readData(Scanner in)
{
    int n=0;Employee[] employees=new Employee[n];
    if(in.hasNextInt())
    {   n=in.nextInt(); 
    in.nextLine();

    for(int i=0;i<n;i++)
        employees[i]=readEmployee(in);}
    else
        in.close();


    return employees;



}

public static void writeEmployee(PrintWriter out, Employee e)
{
    GregorianCalendar calendar=new GregorianCalendar();
    calendar.setTime(e.getHireDay());
    out.println(e.getName()+"|"+e.getSalary()+"|"+calendar.get(Calendar.YEAR)+"|"+(calendar.get(Calendar.MONTH)+1)+"|"+calendar.get(Calendar.DAY_OF_MONTH));
}
public static Employee readEmployee(Scanner in){
    String line=null;

    if(in.hasNextLine()){
    line=in.nextLine();
    String[] tokens=line.split("\\|");
    String name=tokens[0];
    double salary=Double.parseDouble(tokens[1]);
    int year=Integer.parseInt(tokens[2]);
    int month=Integer.parseInt(tokens[3]);
    int day=Integer.parseInt(tokens[4]);return new Employee(name,salary,year,month,day);}
    else
        {
        in.close();
        return null;
        }



}

}
Eclipse环境下的,控制台是这样显示的:
No conaoles to display at this time.
烦请各位大神赐教。

2个回答

调试下,看看try 是不是跳出了。

是跳出了,谢谢,我下去再改改

Csdn user default icon
上传中...
上传图片
插入图片
抄袭、复制答案,以达到刷声望分或其他目的的行为,在CSDN问答是严格禁止的,一经发现立刻封号。是时候展现真正的技术了!
立即提问
相关内容推荐