You are on page 1of 6

EXAMEN DE PROGRAMACION APLICADA

NOMBRES: JUAN TOBIAS ALDAS ULLOA


BAZURTO JORDAN ERICK JOSE
EJERCICIO 1
public class Fichero extends javax.swing.JFrame {

public Fichero() {

initComponents();

generarFichero();

@SuppressWarnings("unchecked")

// <editor-fold defaultstate="collapsed" desc="Generated Code">

private void initComponents() {

jFileChooser1 = new javax.swing.JFileChooser();

jLabel1 = new javax.swing.JLabel();

jLabel2 = new javax.swing.JLabel();

jLabel3 = new javax.swing.JLabel();

jFileChooser2 = new javax.swing.JFileChooser();

setDefaultCloseOperation(javax.swing.WindowConstants.EXIT_ON_CLOSE);

jLabel1.setText("Fichero 1:");

jLabel2.setText("Fichero 2:");
jLabel3.setText("Fichero salida:");

jFileChooser2.addActionListener(new java.awt.event.ActionListener() {

public void actionPerformed(java.awt.event.ActionEvent evt) {

jFileChooser2ActionPerformed(evt);

});

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(52, 52, 52)

.addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.TRAILING)

.addComponent(jLabel2)

.addComponent(jLabel3)

.addComponent(jLabel1))

.addGap(18, 18, 18)

.addComponent(jFileChooser2, javax.swing.GroupLayout.PREFERRED_SIZE, 149,


javax.swing.GroupLayout.PREFERRED_SIZE)

.addContainerGap(639, Short.MAX_VALUE))

);

layout.setVerticalGroup(

layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)

.addGroup(layout.createSequentialGroup()

.addGap(41, 41, 41)

.addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)

.addComponent(jFileChooser2, javax.swing.GroupLayout.PREFERRED_SIZE, 24,


javax.swing.GroupLayout.PREFERRED_SIZE)

.addGroup(layout.createSequentialGroup()
.addComponent(jLabel1)

.addGap(29, 29, 29)

.addComponent(jLabel2)

.addGap(32, 32, 32)

.addComponent(jLabel3)))

.addContainerGap(275, Short.MAX_VALUE))

);

pack();

}// </editor-fold>

public static void generarFichero(){

String[] ficheroUno;

String[] ficheroDos;

String[] ficheroFinal;

ficheroUno = chooser1.getSelectedFile();

ficheroDos = chooser2.getSelectedFile();

ficheroFinal = choose3.getCurrentDirectory();

copiarFichero (ficheroUno, ficheroDos, ficheroFinal);

public static void copiarFichero (String[] ficheroUno, String[] ficheroDos, String ficheroFinal) {

try {

int contador = 0;

int contador2 = 0;
FileOutputStream fileOutput = new FileOutputStream (ficheroFinal, true);

BufferedOutputStream bufferedOutput = new BufferedOutputStream(fileOutput);

int leidos = 0;

int acumulado = 0;

int acumulado1 = 0;

int leidos2 = 0;

int acumulado3 = 0;

while ( contador < ficheroUno.length ) {

FileInputStream fileInput = new FileInputStream(ficheroUno[contador]);

BufferedInputStream bufferedInput = new BufferedInputStream(fileInput);

byte [] array = new byte[1000];

leidos = bufferedInput.read(array);

while (leidos > 0)

bufferedOutput.write(array, 0,leidos);

leidos=bufferedInput.read(array);

acumulado = acumulado + leidos;

contador = contador + 1;

acumulado1 = acumulado;

// Cierre de los ficheros

bufferedOutput.flush();

bufferedInput.close();

}
while ( contador < ficheroDos.length ) {

FileInputStream fileInput = new FileInputStream(ficheroDos[contador]);

BufferedInputStream bufferedInput = new BufferedInputStream(fileInput);

byte [] array = new byte[1000];

leidos2 = bufferedInput.read(array);

while (leidos2 > 0)

bufferedOutput.write(array, 0,leidos);

leidos=bufferedInput.read(array);

acumulado = acumulado + leidos;

contador2 = contador2 + 1;

acumulado3 = acumulado3;

// Cierre de los ficheros

bufferedOutput.flush();

bufferedInput.close();

bufferedOutput.close();

catch (Exception e)

e.printStackTrace();

}
private void jFileChooser2ActionPerformed(java.awt.event.ActionEvent evt) {

// TODO add your handling code here:

You might also like