Java でテキスト ファイルを読み取って配列に割り当てる際に問題が発生しています。プログラムは実行されていますが、null になっています。以下に示すように、コードを最も単純なものに変更してみました。これは実際にはテキスト ファイルをループする必要があるためです。しかし、どこに問題があるのかを簡単に確認できるように、このようにしています。しかし、問題は、なぜまだnullを出力しているのかわからないことです。
これを使用してチェックすると、組み込みメソッドが存在するため、ファイルは確かに指定したディレクトリにあります。
if(ofile.exists()==true){
System.out.println("exist");
}else{
System.out.println("not exist");
}
この背後にあるエラーを特定するには、助けが必要です。なぜnullが返されるのですか。
public static void main(String args[]){
String[] eq=new String[50];
String[]ea=new String[50];
String[]eb=new String[50];
String[] ec=new String[50];
String[]ed=new String[50];
char[] ans=new char[50];
String strtemp;
File ofile= new File("J:\\questions.txt");
BufferedInputStream bis= null;
FileInputStream fis= null;
DataInputStream dis=null;
int ii=0;
int score=0;
System.out.println(eq[1] + "\n" + ea[1] + "\n" + eb[1] + "\n" + ec[1] + "\n" + ed[1] + "\n" + "\n" + "Answer: ");
String strans=x.nextLine();
char y=strans.charAt(0);
if(y==ans[1]){
score++;
}else{
}
try{
fis=new FileInputStream(ofile);
bis=new BufferedInputStream(fis);
dis=new DataInputStream(bis);
while(dis.available()!=0){
eq[1]=dis.readLine(); ea[1]=dis.readLine();
eb[1]=dis.readLine(); ec[1]=dis.readLine();
ed[1]=dis.readLine(); strtemp=dis.readLine();
ans[1]=strtemp.charAt(0);
}
bis.close();
dis.close();
fis.close();
}catch(FileNotFoundException e){
e.printStackTrace();
}catch(IOException e){
e.printStackTrace();
}
}