Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- --JFRAME LEER Y ESCRIBIR
- package archivos;
- import java.io.BufferedReader;
- import java.io.BufferedWriter;
- import java.io.FileNotFoundException;
- import java.io.FileReader;
- import java.io.FileWriter;
- import java.io.IOException;
- import java.util.logging.Level;
- import java.util.logging.Logger;
- /**
- *
- * @author luisgarcia
- */
- public class JFArchivo extends javax.swing.JFrame {
- /**
- * Creates new form NewJFrame
- */
- public JFArchivo() {
- initComponents();
- }
- /**
- * This method is called from within the constructor to initialize the form.
- * WARNING: Do NOT modify this code. The content of this method is always
- * regenerated by the Form Editor.
- */
- @SuppressWarnings("unchecked")
- private void jBLeerActionPerformed(java.awt.event.ActionEvent evt) {
- // TODO add your handling code here:
- String nombre = JTNombreArchivo.getText();
- try {
- FileReader fr = new FileReader(nombre);
- BufferedReader br = new BufferedReader(fr);
- String line="";
- String tota="";
- while((line=br.readLine())!=null){
- tota+=line+"\n"; // por cada linea leida agregamos un salto de linea
- }
- jTextArchivo.setText(tota);
- } catch (FileNotFoundException ex) {
- Logger.getLogger(JFArchivo.class.getName()).log(Level.SEVERE, null, ex);
- } catch (IOException ex) {
- Logger.getLogger(JFArchivo.class.getName()).log(Level.SEVERE, null, ex);
- }
- }
- private void jBEscribirActionPerformed(java.awt.event.ActionEvent evt) {
- // TODO add your handling code here:
- String nombre = JTNombreArchivo.getText();
- String info = " ";
- try {
- FileWriter fw = new FileWriter(nombre);
- BufferedWriter bw = new BufferedWriter(fw);
- info = jTextArchivo.getText();
- bw.write(info);
- bw.newLine();
- bw.close();
- } catch (IOException e) {
- e.printStackTrace();
- }
- }
- /**
- * @param args the command line arguments
- */
- public static void main(String args[]) {
- /* Set the Nimbus look and feel */
- java.awt.EventQueue.invokeLater(new Runnable() {
- public void run() {
- new JFArchivo().setVisible(true);
- }
- });
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement