내 프로그램에서이 부분에 여러 번 오류가 발생했습니다. 기본적으로 unorganized 파일 인 PersonnelInfo.txt에서 입력을 읽은 다음 EmployeeInfo 클래스의 배열로 정렬합니다. 게시자가 문제가 있다고 생각하지 않기 때문에 게시하지 않습니다. 참조 용으로 게시하십시오).자바 쓰기 프로그램 처리되지 않은 예외 유형 IOException
이름 : 직원 이름
에서 정보를 정렬 한 후 (같은 이름, ID 번호, 회사의 제목 등) 프로그램과 같은 정렬됩니다 다른 파일, ORGANIZEDPersonnelInfo.txt, 이것을 기록 여기
는ID :. 여기에 직원 ID는
등
라인은 그것이 "입니다 IOException이 내가 넣어 처리되지 않은 예외 유형은 던졌습니다 내가 얻고한 오류가 ..."정적 FileWriter writeOut "는에있다 주 메소드 d 내의 IOException eclaration하지만 아무것도하지 않았다.
다음으로 "public String toString()"메서드에서 여러 오류가 발생합니다. void로 만들려고 할 때 반환 형식이 Object.toString()과 호환되지 않는다고합니다. String으로 유지하고 null을 반환하면 try/catch를 사용하기를 원하지만 주 오류는 여전히 존재합니다.
도와주세요! "
HR hr = new HR();
out.write(hr.toString());
하지만이 자신의 쓰기 방법을 사용하여 작성합니다 : 이것은 당신이 내용을 인쇄 ...
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을 얻을, 나는 너무 선택할 것 18,872,380 @ 직접 파일에 쓸 수 있지만,이 프로젝트를 위해 우리가하는 방법을 사용해야합니다. – Zach
hr hr = new Hr(); out.write (hr.toString()); – AlexWien
하지만 지금은 좀 추해집니다. – AlexWien