[求助]偶写了个程序,但实现不了预期的结果
import javax.swing.*;import java.awt.*;
import java.awt.event.*;
import java.io.*;
public class a extends JFrame
{
JTextArea box=new JTextArea(100,100);
public a()
{
super("read");
setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
setSize(600,300);
JScrollPane pane=new JScrollPane(box);
getContentPane().add(pane);
try {
//File f=new File(".txt");
FileReader file = new
FileReader("123.txt");
BufferedReader buff = new
BufferedReader(file);
//boolean eof = false;
StringBuffer buf=new StringBuffer();
/* while (!eof) {
String line = buff.readLine();
if (line == null)
eof = true;
else
buf.append(line+"\n");
}*/
String s=null;
if(buff!=null)
{
while((s=buff.readLine())!=null)
{
if(s.startsWith("**"));
//break;
buf.append("\n"+s);
if(s.startsWith("endend"))
{box.setText(buf.toString());
buff.close();}
}
}
} catch (IOException e) {
System.out.println("Error -- " + e.toString());
}
show();
}
public static void main(String args[])
{
new a();
}
}
这个程序的目的是一次只读出一个题目,但是实现不了?各位高手给个意见,谢谢!