각 문자 사이에 공간이 모든 것을 쓰기 :자바 RandomAccessFile의 내가 특정 인덱스의 라인 작성이 기능을 사용
private void write_line(Student s,int index){
try {
Student_pool.seek(0);
Student_pool.seek(index*(25*Integer.SIZE+4*Character.SIZE));
Student_pool.writeChars(s.getId());
Student_pool.writeChars(s.getHw().substring(0,2));
Student_pool.writeChars(".");
Student_pool.writeChars(s.getHw().substring(3,5));
Student_pool.writeChars(s.getPrj().substring(0,2));
Student_pool.writeChars(".");
Student_pool.writeChars(s.getPrj().substring(3,5));
Student_pool.writeChars(s.getMidtermExam().substring(0,2));
Student_pool.writeChars(".");
Student_pool.writeChars(s.getMidtermExam().substring(3,5));
Student_pool.writeChars(s.getFinalExam().substring(0,2));
Student_pool.writeChars(".");
Student_pool.writeChars(s.getFinalExam().substring(3,5));
Student_pool.writeChars("\n");
Student_pool.getFD().sync();
} catch (IOException ex) {
Logger.getLogger(Storagelmpl.class.getName()).log(Level.SEVERE, null, ex);
}
}
을하지만을 나는 결과가 정확하지 않은 파일을 열려고 시도하는 모든 문자가있을 때 그 후에 공간. 결과는 다음과 같습니다
8 1 0 1 8 7 3 1 2 2 0 . 0 0 2 0 . 0 0 2 0 . 0 0 2 0 . 0 0
8 1 0 1 8 8 2 7 5 1 6 . 0 0 1 0 . 0 0 1 3 . 0 0 1 9 . 0 0
내 인코딩 문제와 나의 추구 피연산자 또 다른 문제가있다 생각합니다. 하지만 어떻게 수정해야할지 모르겠다.
내 탐색 함수에 대해 올바른 피연산자를 전달합니까? (나는 25 개의 정수와 각 문자 4 개가 있습니다) – pooya
@pooya : You * don 't *는 한 줄에 4 자입니다 - 쓰는 모든 글자를보세요! 모든 정수를 쓰는 것도 전혀 분명하지 않습니다. 그것은 나에게 문자처럼 보입니다 ... –
처음에는 정수입니다. 정말 고마워요. – pooya