开发者

File won't read into multiple array positions

I'm trying to store each line from a file into an arraylist and then combine two arraylists into one. Currently, when I try this, all the different lines are being stored in one line. I want it to say something like User : Score . However, right now it is showing up like UseruserUsernamePerson : Score. (many different names and only one score). Can anyone see where I'm going wrong here? Also, pardon my poor naming practice. My array lists used to be Vectors, but I changed them into ArrayLists and forgot to change their titles.

public class DisplayScores extends ListActivity{
private ArrayList<String> scoreVector = new ArrayList<String>();
private ArrayList<String> userVector = new ArrayList<String>();
private ArrayList<String> comboVector = new ArrayList<String>();
private int c = 0;
File root = Environment.getExternalStorageDirectory();
File scores = new File(root, "scores.txt");
File users = new File开发者_StackOverflow社区(root, "names.txt");


@Override
protected void onCreate(Bundle savedInstanceState){
    super.onCreate(savedInstanceState);
    String line = null;

    try {
        FileReader scoresFileReader = new FileReader(scores);
        BufferedReader scoresReader = new BufferedReader(scoresFileReader);
        while ((line = scoresReader.readLine())!= null) 
        {
            scoreVector.add(line);
        }
        scoresFileReader.close();
    } catch (IOException e) {
        // TODO Auto-generated catch block
        e.printStackTrace();
    }

    String userLine = null;
    try{
        FileReader userFileReader = new FileReader(users);
        BufferedReader userReader = new BufferedReader(userFileReader);
        while((userLine = userReader.readLine())!= null)
        {
            userVector.add(userLine);
        }
        userReader.close();
    } catch (IOException e){
        e.printStackTrace();
    }

    for(String s : scoreVector)
    {
        comboVector.add(userVector.get(c) + ": " + s);
    }

    this.setListAdapter(new ArrayAdapter<String>(this,
            android.R.layout.simple_list_item_1, comboVector));

}

}


from the code it seems that the value of c is not incrementing.. c is always 0

for(String s : scoreVector)
    {
        comboVector.add(userVector.get(c) + ": " + s);
    }
0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜