일부 값을 가진 텍스트 파일이 있습니다.생성자 배열로 텍스트 파일 읽기 (java)
textfile data
line1row1 line1row2 55
line2row1 line2row2 44
line3row1 line3row2 33
나는 생성자를 만든 데이터 클래스가 있습니다. 배열에 들어가는 데이터는 텍스트 파일에서 읽으 려합니다.
import java.io.*;
import java.util.*;
class Data{
public Data(String entry1, String entry2, int entry3){}
}
public class readData {
public static void main(String[] args) throws Exception{
BufferedReader inFile = new BufferedReader (new FileReader ("scores.txt"));
Data entrydata[] = new Data[3]; //create new constructor array
for(int i = 0; i < entrydata.length; i++){
entrydata[i] = inFile.readLine();
}
}
}
내가 ") (inFile.readLine"에 오류가 ... 데이터를 문자열로 변환 할 수 없습니다 [아래로] 내가 데이터를 하드 코딩 할 수
(여기서 "데이터"클래스를 참조) 하지만 대신
Data entrydata[] = new Data[3];
entrydata [0] = new Data("line1row1 ", "line1row2 ", 55);
entrydata [1] = new Data("line2row1 ", "line2row2 ", 44);
entrydata [2] = new Data("line3row1 ", "line3row2 ", 33);
내가 이렇게 할 이유는 내가 배열에 저장된 informatin에 액세스 할 수 있도록하는 파일에서 읽을 수 싶어요.
가, 감사합니다! 이제 왜 내가 nullpointerexception (나는 더 많은 값을 추가 할 수 있도록하기 위해 초기 3보다 많은 인덱스가있는 배열을 사용하고 있습니다)을 알아 내야합니다. 또한 내 파일의 첫 번째 줄을 무시하고 두 번째 줄에서 개체를 읽기 시작한 다음 nullpointerexception을 throw합니다. – user1031551
발견 된 위치 : 데이터 입력 데이터 [] = 새 데이터 [3]; for (int i = 0; i
user1031551