import java.io.FileNotFoundException;
import java.io.IOException;
import java.io.RandomAccessFile;
import org.eclipse.swt.SWT;
import org.eclipse.swt.events.SelectionAdapter;
import org.eclipse.swt.events.SelectionEvent;
import org.eclipse.swt.layout.RowData;
import org.eclipse.swt.layout.RowLayout;
import org.eclipse.swt.widgets.Button;
import org.eclipse.swt.widgets.Display;
import org.eclipse.swt.widgets.Shell;
import org.eclipse.swt.widgets.Text;
public class n extends SelectionAdapter{
final Display display;
final Shell shell;
private Button bx;
private Button bc;
int n;
private Text tm;
private Text tx;
private RandomAccessFile rf;
n(){
display=new Display();
shell=new Shell(display);
shell.setText("file");
shell.setLayout(new RowLayout(SWT.VERTICAL));
RowData rowdata=new RowData(50,15);
tm=new Text(shell,SWT.WRAP|SWT.V_SCROLL);
tx=new Text(shell,SWT.WRAP|SWT.V_SCROLL);
bx=new Button(shell,SWT.NONE);
bc=new Button(shell,SWT.NONE);
tm.setLayoutData(rowdata);
tx.setLayoutData(rowdata);
bx.setLayoutData(rowdata);
bx.setText("look");
bc.setText("insert");
bc.setLayoutData(rowdata);
bx.addSelectionListener(this);
bc.addSelectionListener(this);
shell.pack();
shell.open();
while (!shell.isDisposed()) {
if (!display.readAndDispatch()) {
display.sleep();
}
}
display.dispose();
}
public static void main(String args[]){
new n();
}
public void widgetSeleted(SelectionEvent e){
if(e.getSource()==bx){
try {
rf=new RandomAccessFile("LX5_5.txt", "rw");
String s = null;
try {
s = rf.readLine();
} catch (IOException e1) {
// TODO 自动生成 catch 块
e1.printStackTrace();
}
n++;
if (n%2==0){
tm.append(s);
}
else{
tx.append(s);
}
} catch (FileNotFoundException e1) {
// TODO 自动生成 catch 块
e1.printStackTrace();
}
if(e.getSource()==bc){
try{
rf=new RandomAccessFile("LX5_5.txt", "rw");
rf.seek(rf.length());
rf.writeChars(tm.getText());
rf.writeChars(tx.getText());
rf.close();
}
catch (FileNotFoundException fnoe) {}
catch (IOException ioe) {}
}
}
}
}
还有如下异常: