Abrir y Guardar Archivo de Texto TXT NetBeans
Вставка
- Опубліковано 8 лют 2025
- Abrir documento de texto (txt), en el formulario, mostrando el contenido, poder modificar el contenido y guardar los cambios.
Si te gusto el video, No Olvides seguir nuestra pagina de facebook: / oversystemperu
No es lo que buscaba pero esta maravilloso!!!!
EXCELENTE VIDEO INSTRUCTORA, MUCHAS GRACIAS.
Tremendo, me ayudaste en mi parcial, mas que por la cuarentena el Ing no explica las clases para nada
Me pasas el programa porfavor?
Jajja lo mismo me pasa, el ingeniero no explica nada y quiere que el hagamos un programa full
Este vídeo me ayudo bastante, gracias!
Lo bueno de tus videos es que usas la parte gráfica y no la consola como los demás.
La parte grafica es lo mismo, solo q decidis qu carcteristicas colocrle
INCREÍBLE VÍDEO SOLO QUE FALTO COMENTARLO :V
excelente tutorial bastante util y funciona!
por si acaso no sabras como configurar un boton buscar con un archivo txt??
Me ayudo mucho para la practica, solo falto la explicacion. Saludos.
Maravilloso, muchísimas gracias.
Aquí andamos 4 pendejos copiando tu código para una tarea de la universidad.
Somos 5
somos 6
somos 7
muy bien bro, gracias!!!!!
me salvaste bro gracias
Gracias Brother me sirvio mucho esto!!
calidad amigo buen contenido
una pregunta si simplemente quiero que se guarden los cambios que hice en el archivo como le aria? simplemte que le de al boton y me guarde los cambios sin mostrarme la ventana
Se puede hacer lo mismo con un JList?
Gracias!
Buenas tardes, tengo un problema, es que uso una "Lista" no un "Area de texto", me ayudas?
Hola como esta me gusta su canal explica de manera entendible.Necisto una ayuda quiero que la información que este en el archivo plano lo mande ala una base de datos
Buen vídeo, una pregunta, no tendrás el código de duplicado de estos archivos de texto?
Y PARA MODIFICARLO?
en el caso que lo quiera guardar dentro de un paquete del proyecto, como seria?
Me refiero a como guardar en el mismo formato y abrirlo igual en otra computadora
exelente video solo k te falto poner el codigo en la descripcion.
No es osmany??
Alguien sabe que es el ascci y que hace dentro del while (su funcion)?
Son los caracteres
en el minuto 8:51 fila 132 pusiste textarea.setText(documento);
pero yo quiero ponerle jtable y sale un error.
ayudame hay gracias.
como lo resolviste? :c
@@javierfidel5512 Pudiste resolverlo? :c
Pudiste guardar un jtable?
alguien me podria ayudar en vez de cargar en un txt quiero cargar en eun jtable
me gusto
yo quisiera guardar muchos jtextfield en un txt, ¿ cómo podría hacer eso?
Ala :v yo igual
Puedes aplicarlo con un getText() y con un boton que decidas que guarde.
No veo el código, por qué no aumentas el campo visual o dejas el código en un archivo PDF?? ¬¬ y no explicas nada.
Hubieses dejado el código fuente
Usted no es mi maestro :v ya que es el mismo (igualitoooo) codigo que me mando mi maestro :v???
por q no hablas seria mucho mejor
8:15 De donde sacas el txtarea?
Es el area del texto, solamente le cambio el nombre
Explique este código amigo
loco puedes hacer trabajos en c#
si
podrias subir el programa ?
Alguna buena persona que me pueda mandar el código por favor;)
package binario;
import java.io.File;
import java.io.FileInputStream;
import java.io.FileOutputStream;
import javax.swing.JFileChooser;
import javax.swing.JOptionPane;
/**
*
* @author gomez
*/
public class binario1 extends javax.swing.JFrame {
JFileChooser seleccionar= new JFileChooser();
File archivo;
FileInputStream entrada;
FileOutputStream salida;
/**
* Creates new form binario1
*/
public binario1() {
initComponents();
}
public String AbrirArchivo (File archivo){
String documento ="";
try {
entrada=new FileInputStream(archivo);
int ascci;
while((ascci=entrada.read())!=-1){
char caracter=(char)ascci;
documento+=caracter;
}
} catch (Exception e){
}
return documento;
}
public String GuardarArchivo(File archivo,String documento){
String mensaje =null;
try {
salida=new FileOutputStream(archivo);
byte[] bytxt=documento.getBytes();
salida.write(bytxt);
mensaje="archivo guardado";
} catch (Exception e){
}
return mensaje;
}
/**
* 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 initComponents() {
btnabrir = new javax.swing.JButton();
btnguardar = new javax.swing.JButton();
jScrollPane1 = new javax.swing.JScrollPane();
txtarea = new javax.swing.JTextArea();
setDefaultCloseOperation(javax.swing.WindowConstants.EXIT_ON_CLOSE);
btnabrir.setText("Abrir Documento");
btnabrir.addActionListener(new java.awt.event.ActionListener() {
public void actionPerformed(java.awt.event.ActionEvent evt) {
btnabrirActionPerformed(evt);
}
});
btnguardar.setText("Guardar Documento");
btnguardar.addActionListener(new java.awt.event.ActionListener() {
public void actionPerformed(java.awt.event.ActionEvent evt) {
btnguardarActionPerformed(evt);
}
});
txtarea.setColumns(20);
txtarea.setRows(5);
jScrollPane1.setViewportView(txtarea);
javax.swing.GroupLayout layout = new javax.swing.GroupLayout(getContentPane());
getContentPane().setLayout(layout);
layout.setHorizontalGroup(
layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
.addGroup(layout.createSequentialGroup()
.addGap(25, 25, 25)
.addComponent(jScrollPane1, javax.swing.GroupLayout.PREFERRED_SIZE, 353, javax.swing.GroupLayout.PREFERRED_SIZE)
.addContainerGap(22, Short.MAX_VALUE))
.addGroup(layout.createSequentialGroup()
.addContainerGap(javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)
.addComponent(btnabrir)
.addGap(18, 18, 18)
.addComponent(btnguardar)
.addGap(60, 60, 60))
);
layout.setVerticalGroup(
layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
.addGroup(layout.createSequentialGroup()
.addGap(31, 31, 31)
.addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
.addComponent(btnabrir)
.addComponent(btnguardar))
.addGap(18, 18, 18)
.addComponent(jScrollPane1, javax.swing.GroupLayout.PREFERRED_SIZE, 216, javax.swing.GroupLayout.PREFERRED_SIZE)
.addContainerGap(javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE))
);
pack();
}//
private void btnabrirActionPerformed(java.awt.event.ActionEvent evt) {
// TODO add your handling code here:
if(seleccionar.showDialog(null, "abrir")==JFileChooser.APPROVE_OPTION){
archivo=seleccionar.getSelectedFile();
if(archivo.canRead()){
if(archivo.getName().endsWith("txt")){
String documento=AbrirArchivo(archivo);
txtarea.setText(documento);
}else{
JOptionPane.showMessageDialog(null,"Archivo no compatible" );
}
}
}
}
private void btnguardarActionPerformed(java.awt.event.ActionEvent evt) {
// TODO add your handling code here:
if(seleccionar.showDialog(null, "Guardar")==JFileChooser.APPROVE_OPTION){
archivo=seleccionar.getSelectedFile();
if (archivo.getName().endsWith("txt")){
String Documento=txtarea.getText();
String mensaje=GuardarArchivo(archivo, Documento);
if(mensaje!=null){
JOptionPane.showMessageDialog(null, mensaje);
}else{
JOptionPane.showConfirmDialog(null, "Archivo no cumpatible");
}
}else{
JOptionPane.showMessageDialog(null,"Guardar Documento de Texto");
}
}
}
/**
* @param args the command line arguments
*/
public static void main(String args[]) {
/* Set the Nimbus look and feel */
//
/* If Nimbus (introduced in Java SE 6) is not available, stay with the default look and feel.
* For details see download.oracle.com/javase/tutorial/uiswing/lookandfeel/plaf.html
*/
try {
for (javax.swing.UIManager.LookAndFeelInfo info : javax.swing.UIManager.getInstalledLookAndFeels()) {
if ("Nimbus".equals(info.getName())) {
javax.swing.UIManager.setLookAndFeel(info.getClassName());
break;
}
}
} catch (ClassNotFoundException ex) {
java.util.logging.Logger.getLogger(binario1.class.getName()).log(java.util.logging.Level.SEVERE, null, ex);
} catch (InstantiationException ex) {
java.util.logging.Logger.getLogger(binario1.class.getName()).log(java.util.logging.Level.SEVERE, null, ex);
} catch (IllegalAccessException ex) {
java.util.logging.Logger.getLogger(binario1.class.getName()).log(java.util.logging.Level.SEVERE, null, ex);
} catch (javax.swing.UnsupportedLookAndFeelException ex) {
java.util.logging.Logger.getLogger(binario1.class.getName()).log(java.util.logging.Level.SEVERE, null, ex);
}
//
/* Create and display the form */
java.awt.EventQueue.invokeLater(new Runnable() {
public void run() {
new binario1().setVisible(true);
}
});
}
// Variables declaration - do not modify
private javax.swing.JButton btnabrir;
private javax.swing.JButton btnguardar;
private javax.swing.JScrollPane jScrollPane1;
private javax.swing.JTextArea txtarea;
// End of variables declaration
}