部分代码,如下:读txt里的东西,然后显示,现在这样的情况是str里的东西好像只有最后一行的,没有全存进去 button1.addActionListener(new button1Listener());
button2.addActionListener(new button2Listener());
button3.addActionListener(new button3Listener());
File f1=new File("1.txt");
try {
BufferedReader br=new BufferedReader(new FileReader(f1));
String line;
while((line=br.readLine())!=null){
line=br.readLine();
 //result.clone();
 String[] result = line.split(",");
   
    str.add(result[0]);
    str.add(result[1]);
} } catch (IOException e1) {
// TODO 自動生成された catch ブロック
e1.printStackTrace();
}
}class button1Listener implements ActionListener{ @Override
public void actionPerformed(ActionEvent e) {    // String question = result[0];

String question=str.remove(0);
    text1.setText(question); }
} class button2Listener implements ActionListener{ @Override
public void actionPerformed(ActionEvent e) {
// TODO 自動生成されたメソッド・スタブ
String answer = str.remove(0);
    text2.setText(answer); }
}

解决方案 »

  1.   


    try {
                BufferedReader br=new BufferedReader(new FileReader(f1));
                String line;
                while((line=br.readLine())!=null){
                line=br.readLine();                      //读了两次。。?
                 //result.clone();
                 String[] result = line.split(",");
               
                str.add(result[0]);
                str.add(result[1]);
                }        } catch (IOException e1) {
                // TODO 自動生成された catch ブロック
                e1.printStackTrace();
            }
      

  2.   

                while((line=br.readLine())!=null){
                line=br.readLine();                      //读了两次。。?,在while里面读一行,此处读的就是下一行了?这样就间隔着跳过了一行
                 //result.clone();
                 String[] result = line.split(",");
               
                str.add(result[0]);
                str.add(result[1]);
                }楼主试试是不是在这样?
      

  3.   

    嗯     把line=br.readLine();                      注释掉  就ok了~