.txt 파일에서 double을 읽고 목록에 모두 넣으려고합니다. 여기 .txt 파일에서 목록으로 복식을 읽는 것
지금까지 내 코드입니다 ->(. 나는 목록에 복식을 넣어 한 파일을 요청하고 데이터 스트림을 얻고,하는 하나 개의 방법이)
public InputFile() throws MyException {
fileIn = null;
dataIn = null;
do {
filename = JOptionPane.showInputDialog("What is the file called? ");
try {
fileIn = new FileInputStream((filename + ".txt"));
dataIn = new DataInputStream(fileIn);
return;
}
catch (FileNotFoundException e) {
JOptionPane.showMessageDialog(null, "There is no "+filename + ".txt");
}
}
while ( Question.answerIsYesTo("Do you want to retype the file name") );
throw new MyException("No input file was chosen");
}
그 부품이 잘 작동합니다. 인덱스 : 0, 파일 크기 : 0
어떤 아이디어
java.lang.IndexOutOfBoundsException -
public ProcessMain() { boolean EOF = false; List <Double> allNumbers = new ArrayList <Double>() ; try { InputFile inputFile = new InputFile(); while(EOF == false) { try { allNumbers.add(inputFile.dataIn.readDouble()); } catch(EOFException e){ EOF = true; } } // List manipulation here. I have no problems with this part. } catch (Exception e) { System.out.println(e); } System.out.println(allNumbers);
나는 다음을 얻을?
'InputFile2'란 무엇입니까? 'InputFile inputFile2 = new InputFile()'을 원하셨습니까? 어떤 코드 라인이 예외를 던집니까? –
예, 실수로 2 인치를 넣습니다. –
어떤 줄이 예외를 던집니까? –