Deep_Mind 2016-07-24 13:45 采纳率: 0%
浏览 980

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

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条回答

  • devmiao 2016-07-24 15:52
    关注

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

    评论

报告相同问题?

悬赏问题

  • ¥15 ads仿真结果在圆图上是怎么读数的
  • ¥20 Cotex M3的调试和程序执行方式是什么样的?
  • ¥20 java项目连接sqlserver时报ssl相关错误
  • ¥15 一道python难题3
  • ¥15 用matlab 设计一个不动点迭代法求解非线性方程组的代码
  • ¥15 牛顿斯科特系数表表示
  • ¥15 arduino 步进电机
  • ¥20 程序进入HardFault_Handler
  • ¥15 oracle集群安装出bug
  • ¥15 关于#python#的问题:自动化测试