为什么我的数组会从我正在阅读的文件中删除零?

ash*_*ion 5 java arrays

好吧,我试图读取一个看起来像这样的文本文件:

FTFFFTTFFTFT
3054 FTFFFTTFFTFT
4674 FTFTFFTTTFTF
......等

当我正在阅读它时,一切都编译并且工作得非常好,将所有内容放入这样的数组中:

studentID [0] = 3054
studentID [1] = 4674
......等

studentAnswers [0] = FTFFFTTFFTFT
studentAnswers [1] = FTFTFFTTTFTF

但是,如果studentID具有前导零或尾随零,当我使用System.out.println();打印它时,它会删除前导零和尾随零!我觉得这很简单,我需要复制数组或其他东西.谢谢 :)

以下是我的代码:

public static String[] getData() throws IOException {
  int total = 0;
  int[] studentID = new int[127];
  String[] studentAnswers = new String[127];

  String line = reader.readLine();
  String answerKey = line;
  StringTokenizer tokens;
  while((line = reader.readLine()) != null) {
    tokens = new StringTokenizer(line);
    studentID[total] = Integer.parseInt(tokens.nextToken());
    studentAnswers[total] = tokens.nextToken();
    System.out.println(total + " " +studentID[total]);
    total++;
  }
  return studentAnswers;
}
Run Code Online (Sandbox Code Playgroud)

Ara*_*raK 10

String而不是int.作为一般规则,使用整数类型进行计算.