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 如何让企业微信机器人实现消息汇总整合
  • ¥50 关于#ui#的问题:做yolov8的ui界面出现的问题
  • ¥15 如何用Python爬取各高校教师公开的教育和工作经历
  • ¥15 TLE9879QXA40 电机驱动
  • ¥20 对于工程问题的非线性数学模型进行线性化
  • ¥15 Mirare PLUS 进行密钥认证?(详解)
  • ¥15 物体双站RCS和其组成阵列后的双站RCS关系验证
  • ¥20 想用ollama做一个自己的AI数据库
  • ¥15 关于qualoth编辑及缝合服装领子的问题解决方案探寻
  • ¥15 请问怎么才能复现这样的图呀