0
我目前正在嘗試讀取文件並相應地存儲它們。我從文本文件中讀取並將它們存儲到一個數組列表中,現在我只是試圖存儲這些數字,但是當我打印出數組列表的內容時,我仍然得到相同的framenumber。我的循環有什麼問題?
內容我的文本文件
FrameNumber: 49136
FrameNumber: 49137
FrameNumber: 49138
FrameNumber: 49139
FrameNumber: 49140
FrameNumber: 49141
288
200
3848
287
191
3859
283
145
3849
我ReadFile函數
public void readFile()
{
ArrayList<Frame> frameList = new ArrayList<Frame>();
ArrayList<Joint> jointList = new ArrayList<Joint>();
ArrayList<String> al = new ArrayList<String>();
Frame retrievedFrame = new Frame();
Joint tempJoint = new Joint();
Coordinate tempCoordinate = new Coordinate();
try
{
File file = new File(filename);
if(!file.exists())
{
file.createNewFile();
}
BufferedReader bufferedReader = new BufferedReader(new InputStreamReader(new FileInputStream(file),"UTF-8"));
BOMSkipper.skip(bufferedReader);
String line = bufferedReader.readLine();
while (line != null)
{
al.add(line);
line = bufferedReader.readLine();
}
bufferedReader.close();
}
catch (IOException e)
{
e.printStackTrace();
}
String temp;
for (int i = 0; i < al.size(); i++)
{
if (al.get(i).contains("FrameNumber:") == true)
{
temp = al.get(i).replace("FrameNumber: ", "");
temp = temp.trim();
retrievedFrame.setFrameNumber(Integer.parseInt(temp));
frameList.add(retrievedFrame);
System.out.println("Frame Detected");
}
else
{
System.out.println("Not Frame");
}
}
for (int j = 0; j < frameList.size(); j++)
{
System.out.println(frameList.size());
System.out.println("Frame Number: " + frameList.get(j).getFrameNumber());
}
}
啊我看。我認爲它會用新值替換當前值。謝謝 – John