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 关于#hadoop#的问题
  • ¥15 (标签-Python|关键词-socket)
  • ¥15 keil里为什么main.c定义的函数在it.c调用不了
  • ¥50 切换TabTip键盘的输入法
  • ¥15 可否在不同线程中调用封装数据库操作的类
  • ¥15 微带串馈天线阵列每个阵元宽度计算
  • ¥15 keil的map文件中Image component sizes各项意思
  • ¥20 求个正点原子stm32f407开发版的贪吃蛇游戏
  • ¥15 划分vlan后,链路不通了?
  • ¥20 求各位懂行的人,注册表能不能看到usb使用得具体信息,干了什么,传输了什么数据