bom dia
Estou com um problema, eu tenho que fazer uma comparação de arquivos(consegui) e dentro desta comparação listar somente arquivos com a extensão “.zip, .rar” e dentro desta pesquisa ao selecionar o arquivos ele descompactar para realizar a comparação de arquivos.
Alguem poderia me ajudar
meu codigo está assim :
import java.awt.EventQueue;
import javax.swing.JFrame;
import javax.swing.JPanel;
import javax.swing.border.EmptyBorder;
import javax.swing.JTextField;
import javax.swing.JButton;
import javax.swing.JFileChooser;
import java.awt.event.ActionListener;
import java.io.File;
import java.util.ArrayList;
import java.util.Arrays;
import java.util.List;
import java.util.Scanner;
import java.util.stream.Collectors;
import java.awt.event.ActionEvent;
import javax.swing.JLabel;
public class TesteArquivo extends JFrame {
/**
*
*/
private static final long serialVersionUID = 1L;
protected static final Object LerArquivo = null;
private JPanel contentPane;
private static JTextField txtSelecioneUmaPastaarquivo;
private JTextField textField_1;
private JButton btnNewButton_1;
private JButton comparar;
private JTextField textField_2;
/**
* Launch the application.
*/
public static void main(String[] args) {
EventQueue.invokeLater(new Runnable() {
public void run() {
try {
TesteArquivo frame = new TesteArquivo();
frame.setVisible(true);
} catch (Exception e) {
e.printStackTrace();
}
}
});
}
/**
* Create the frame.
*/
public TesteArquivo() {
setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
setBounds(100, 100, 615, 500);
contentPane = new JPanel();
contentPane.setBorder(new EmptyBorder(5, 5, 5, 5));
setContentPane(contentPane);
contentPane.setLayout(null);
txtSelecioneUmaPastaarquivo = new JTextField();
txtSelecioneUmaPastaarquivo.setBounds(43, 72, 180, 23);
contentPane.add(txtSelecioneUmaPastaarquivo);
txtSelecioneUmaPastaarquivo.setColumns(10);
JFileChooser fc = new JFileChooser();
JButton btnNewButton = new JButton("...");
btnNewButton.setBounds(233, 72, 50, 22);
btnNewButton.addActionListener(new ActionListener() {
public void actionPerformed(ActionEvent e) {
fc.setFileSelectionMode(JFileChooser.FILES_AND_DIRECTORIES);
if(fc.showOpenDialog(contentPane) == JFileChooser.APPROVE_OPTION){
txtSelecioneUmaPastaarquivo.setText(fc.getSelectedFile().getAbsolutePath());
}
}
});
contentPane.add(btnNewButton);
textField_1 = new JTextField();
textField_1.setBounds(313, 72, 180, 22);
contentPane.add(textField_1);
textField_1.setColumns(10);
btnNewButton_1 = new JButton("...");
btnNewButton_1.setBounds(510, 72, 56, 23);
btnNewButton_1.addActionListener(new ActionListener() {
public void actionPerformed(ActionEvent e) {
fc.setFileSelectionMode(JFileChooser.FILES_AND_DIRECTORIES);
if(fc.showOpenDialog(contentPane) == JFileChooser.APPROVE_OPTION){
textField_1.setText(fc.getSelectedFile().getAbsolutePath());
}
}
});
contentPane.add(btnNewButton_1);
comparar = new JButton("Comparar");
comparar.setBounds(472, 424, 98, 32);
comparar.addActionListener(new ActionListener() {
public void actionPerformed(ActionEvent e) {
String pasta1 = txtSelecioneUmaPastaarquivo.getText();
File pasta = new File(pasta1);
try {
List<String> list = Arrays.stream(pasta.list()).collect(Collectors.toList());
String file1 = textField_1.getText();
File file = new File(file1);
Scanner scanner = new Scanner(file);
List<String> lista = new ArrayList<>();
while (scanner.hasNext()) {
lista.add(scanner.next());
}
scanner.close();
StringBuilder sb = new StringBuilder();
lista.stream().forEach(f -> { //list
if (!list.contains(f)) { //lista
if (sb.length() == 0) {
sb.append(f);
} else {
sb.append(", " + f);
}
}
});
System.out.println(sb.toString());
textField_2.setText(sb.toString());
} catch (Exception i) {
i.printStackTrace();
}
}
});
contentPane.add(comparar);
textField_2 = new JTextField();
textField_2.setBounds(43, 147, 523, 266);
contentPane.add(textField_2);
textField_2.setColumns(10);
JLabel lblNewLabel = new JLabel("Arquivo 1");
lblNewLabel.setBounds(43, 47, 73, 14);
contentPane.add(lblNewLabel);
JLabel lblNewLabel_1 = new JLabel("Arquivo 2");
lblNewLabel_1.setBounds(313, 47, 64, 14);
contentPane.add(lblNewLabel_1);
}
}