我正在使用此程序的這一部分獲得多個erros。它的基本功能是從無組織文件PersonnelInfo.txt中讀取輸入,並將其分類到EmployeeInfo類中的一個數組中(不張貼,因爲我不相信問題在於該類,如果你們想要的話,我會張貼以供參考)。Java寫出程序未處理的異常類型IOException
排序後的信息(如姓名,身份證號,標題,公司等)的程序寫入該到另一個文件,ORGANIZEDPersonnelInfo.txt,將被歸類爲這樣的:
名稱:員工姓名這裏
ID:這裏的員工ID
等
一個錯誤,我得到的是「靜態的FileWriter WriteOut的......」行,這是「未處理的異常類型爲IOException我把罰球主方法中的IOException d但它沒有做任何事情。
接下來,在「public String toString()」方法中,我收到多個錯誤。當我嘗試使其無效時,它表示返回類型與Object.toString()不兼容。當我把它作爲一個String並返回null時,它希望我使用try/catch,但主要錯誤仍然存在。
請幫忙!這是越來越漂亮沮喪......
import java.io.*;
import java.util.Scanner;
public class HR {
static EmployeeInfo[] employee = new EmployeeInfo[4];
static FileWriter writeOut = new FileWriter("/Users/zach/Documents/workspace/Dec. 10, 2012/src/ORAGNIZEDPersonnelInfo.txt");
static BufferedWriter out = new BufferedWriter(writeOut);
public static void main(String[] args) throws IOException {
File PersonnelInfo = new File("/Users/zach/Documents/workspace/Dec. 10, 2012/src/PersonnelInfo.txt");
Scanner inputFile = new Scanner(PersonnelInfo);
int numOfEmployees = Integer.parseInt(inputFile.nextLine());
System.out.println("Number of employees: " + numOfEmployees);
for (int i = 0; i < 4; i++) {
String name = inputFile.nextLine();
String ID = inputFile.nextLine();
String title= inputFile.nextLine();
String startDate = inputFile.nextLine();
employee[i] = new EmployeeInfo(name, ID, title, startDate);
}
listEmployeeInfo();
employee.toString();
}
public String toString() {
for (EmployeeInfo i: employee) {
out.write("Name: " + i.getName());
out.write("ID: " + i.getID());
out.write("Title: " + i.getTitle());
out.write("Start Date: " + i.getStartDate());
}
return null;
}
其寫入文件,但我得到[LEmployeeInfo; @ 18872380 我太會選擇直接寫入文件,但對於這個項目,我們需要使用的方法。 – Zach
Hr hr = new Hr(); out.write(hr.toString()); – AlexWien
但現在它變得有點醜陋。 – AlexWien