Download as doc, pdf, or txt
Download as doc, pdf, or txt
You are on page 1of 1

import java.awt.

*;
import java.awt.event.*;
import java.io.*;

public class Mfile1 implements ActionListener, WindowListener{


Frame f;
Button b;
TextArea ta;
FileInputStream fis;

public void inicio()


{
f=new Frame("Archivo");
b=new Button("Abrir");
ta=new TextArea();
b.addActionListener(this);
f.add("Center",ta);
f.add("South",b);
f.setSize(350,250);
f.setVisible(true);
f.addWindowListener(this);
}

public void actionPerformed(ActionEvent ae){


String s=ae.getActionCommand();
if("Abrir" ==s){
byte b[]=new byte[1024];
int i;
try{
fis=new FileInputStream("C:/Prueba.txt");
}catch(FileNotFoundException e){ }

try
{
i=fis.read(b);
}
catch(IOException ioe){}
s=new String(b,0);
ta.setText(s);

}
}

public void windowClosing(WindowEvent we)


{
f.setVisible(false);
}

public void windowClosed(WindowEvent we)


{ }
public void windowOpened(WindowEvent we)
{ }
public void windowIconified( WindowEvent we ) {}
public void windowDeiconified(WindowEvent we) {}
public void windowActivated (WindowEvent we){}
public void windowDeactivated(WindowEvent we){}
}

You might also like