ArrayList 저장소의 학생 배열을 사용하여 파일 I/O를 사용하여 텍스트 파일에 쓰고 있습니다. 그게 다 좋고 좋아. 나는 일하고있다. 그러나 실제 텍스트 파일에서 세부 정보는 한 줄로 인쇄하고 읽는 것입니다.RandomAccessFile 텍스트 파일로 인쇄 문제
누구든지이 문제를 볼 수 있습니까? -----------------
MainApp
import java.io.RandomAccessFile;
public class MainApp
{
public static void main(String[] args) throws Exception
{
new MainApp().start();
}
public void start()throws Exception
{
StudentStore details = new StudentStore();
Student a = new Student("Becky O'Brien", "DKIT26", "0876126944", "[email protected]");
Student b = new Student("Fabio Borini", "DKIT28", "0876136944", "[email protected]");
Student c = new Student("Gaston Ramirez", "DKIT29", "0419834501", "[email protected]");
Student d = new Student("Luis Suarez", "DKIT7", "0868989878", "[email protected]");
Student e = new Student("Andy Carroll", "DKIT9", "0853456788", "[email protected]");
details.add(a);
details.add(b);
details.add(c);
details.add(d);
details.add(e);
//details.print();
RandomAccessFile file = new RandomAccessFile("ContactDetails.txt","rw");
//getBytes() returns an array of bytes.
//Because i have put the store in a static Array.(I done this because i could find no other
//Simple way to write a Student Object.)
//None of the methods of the RandomAccessFile write class worked with this.
Student[] students = {a,b,c,d,e};
for (int i = 0; i < students.length; i++)
{
byte[] bytes = students[i].toString().getBytes();
for(byte byteWrite : bytes)
{
file.writeByte(byteWrite);
}
}
final int Record_Length = 30;
int recordNumber = 1;
file.seek((recordNumber) * Record_Length);
String code ="";
for(int i = 0; i < 4; i++)
{
code += file.readLine();
}
System.out.println(code);
file.close();
}
}
ToString
//---------------------------------------------------------------------------
// toString.
//---------------------------------------------------------------------------
public String toString()
{
return "---------------------------Student--------------------------- " +
"\nStudent Name:" + studentName +
"\nStudent Id:"+ studentId +
"\nStudent Telephone Number:"+ studentTelephoneNumber +
"\nStudent Email:" + studentEmail +"\n\n";
}
출력 덴트 :
여기내 코드입니다 ---------- 학생 이름 : Becky O'Brien 학생 : DKIT26 학생 번호 : 0876126944
감사합니다. 또한 IDE에서 사용하는 텍스트 파일을로드 할 때 모든 것이 순서대로 이루어집니다. 하지만 프로젝트 폴더에서 한 줄에 모두 열 때. 어떤 생각이야? – Pendo826
그래서 IDE의 패키지 탐색기에서 파일을 열면 정상적으로 나타납니다.하지만 시스템 파일 탐색기로 가서 열면 줄 바꿈이 없습니다? –
그 모든 것을 하나의 단일 라인에 입력하십시오. 솔로 션을 사용하면 100 % 올바른 형식으로 읽음을 표시했기 때문에 의미가 없습니다. S – Pendo826