Usando uma ferramenta de comparação como Além da comparação , o KDiff3 , ou Perforce deve ser suficiente.
ATUALIZAÇÃO:
Eu estava me sentindo generoso esta manhã, então eu joguei isso para você. Deve fazer o que quiser.
Algumasnotas:
1.)Estecódigoirálidarcomduplicatas.Porexemplo,seumalinhacomomesmotextoaparecerduasvezesnoarquivopequeno,espera-sequeelaapareçaduasvezesnoarquivogrande.
2.)Estecódigoignoraaordemdaslinhasconformeocasodeuso.
3.)Pequenobugsobrelinhasembranconofinaldeumarquivoqueeunãoqueriamexer.Essecódigotrataumalinhaembrancocomoumalinhacomoqualqueroutralinha,desdequenãoestejanofinaldoarquivo,casoemqueumalinhaembrancoépermitida(eignorada).Porexemplo,seoarquivopequenotiver3linhasembranconofinaldoarquivoenenhumaoutralinhaembranco,espera-sequeoarquivograndetenhapelomenos2linhasembranconomeiodasoutraslinhasou3linhasembranconofimdoarquivo.
Paraexecutar:
1.)Verifiquesevocêtemum
2.) Verifique se o java está no seu caminho. Se você estiver em um sistema Windows, vá ao Painel de controle > Sistema > Configurações avançadas do sistema > Variáveis de Ambiente e selecione Path
na seção Variáveis do Sistema. Anexe a localização da sua pasta bin do JDK à variável path, certificando-se de separá-la da entrada anterior com um ponto e vírgula. Algo como isto:
C:\Program Files (x86)\Java\jdk1.6.0_38\bin;
3.) Copie o código abaixo em um arquivo chamado FileLineComparator.java
4.) Abra um prompt de comando e navegue até o diretório com o arquivo que você acabou de criar
5.) Digite javac FileLineComparator.java
6.) Digite java -cp . FileLineComparator
7.) Aproveite!
import java.io.*;
import java.util.ArrayList;
import javax.swing.JFileChooser;
import javax.swing.JOptionPane;
public class FileLineComparator extends javax.swing.JFrame {
public FileLineComparator() {
initComponents();
}
@SuppressWarnings( "unchecked" )
// <editor-fold defaultstate="collapsed" desc="Generated Code">
private void initComponents() {
fileChooser = new javax.swing.JFileChooser();
smallFileTextField = new javax.swing.JTextField();
smallFileLabel = new javax.swing.JLabel();
largeFileLabel = new javax.swing.JLabel();
largeFileTextField = new javax.swing.JTextField();
outputFileLabel = new javax.swing.JLabel();
outputFileTextField = new javax.swing.JTextField();
goButton = new javax.swing.JButton();
smallFileButton = new javax.swing.JButton();
largeFileButton = new javax.swing.JButton();
outputFileButton = new javax.swing.JButton();
setDefaultCloseOperation(javax.swing.WindowConstants.EXIT_ON_CLOSE);
smallFileLabel.setText("Small text file:");
largeFileLabel.setText("Large text file:");
outputFileLabel.setText("Output file:");
goButton.setText("Go!");
goButton.addMouseListener(new java.awt.event.MouseAdapter() {
public void mouseClicked(java.awt.event.MouseEvent evt) {
goButtonMouseClicked(evt);
}
});
smallFileButton.setText("Browse");
smallFileButton.addMouseListener(new java.awt.event.MouseAdapter() {
public void mouseClicked(java.awt.event.MouseEvent evt) {
smallFileButtonMouseClicked(evt);
}
});
largeFileButton.setText("Browse");
largeFileButton.addMouseListener(new java.awt.event.MouseAdapter() {
public void mouseClicked(java.awt.event.MouseEvent evt) {
largeFileButtonMouseClicked(evt);
}
});
outputFileButton.setText("Browse");
outputFileButton.addMouseListener(new java.awt.event.MouseAdapter() {
public void mouseClicked(java.awt.event.MouseEvent evt) {
outputFileButtonMouseClicked(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()
.addContainerGap()
.addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING, false)
.addGroup(layout.createSequentialGroup()
.addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
.addGroup(layout.createSequentialGroup()
.addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
.addComponent(largeFileLabel)
.addComponent(smallFileLabel))
.addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
.addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.TRAILING, false)
.addComponent(outputFileTextField, javax.swing.GroupLayout.Alignment.LEADING, javax.swing.GroupLayout.DEFAULT_SIZE, 194, Short.MAX_VALUE)
.addComponent(largeFileTextField, javax.swing.GroupLayout.Alignment.LEADING)
.addComponent(smallFileTextField)))
.addComponent(outputFileLabel))
.addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
.addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
.addComponent(largeFileButton)
.addComponent(smallFileButton)
.addComponent(outputFileButton)))
.addComponent(goButton, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE))
.addContainerGap(16, Short.MAX_VALUE))
);
layout.setVerticalGroup(
layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
.addGroup(layout.createSequentialGroup()
.addContainerGap()
.addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
.addComponent(smallFileTextField, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
.addComponent(smallFileLabel)
.addComponent(smallFileButton))
.addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
.addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
.addComponent(largeFileLabel)
.addComponent(largeFileTextField, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
.addComponent(largeFileButton))
.addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
.addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
.addComponent(outputFileTextField, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
.addComponent(outputFileLabel)
.addComponent(outputFileButton))
.addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
.addComponent(goButton, javax.swing.GroupLayout.PREFERRED_SIZE, 62, javax.swing.GroupLayout.PREFERRED_SIZE)
.addContainerGap(javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE))
);
pack();
}// </editor-fold>
private void smallFileButtonMouseClicked( java.awt.event.MouseEvent evt ) {
setSelectedFile( FILE_TYPES.SMALL );
}
private void largeFileButtonMouseClicked( java.awt.event.MouseEvent evt ) {
setSelectedFile( FILE_TYPES.LARGE );
}
private void outputFileButtonMouseClicked( java.awt.event.MouseEvent evt ) {
setSelectedFile( FILE_TYPES.OUTPUT );
}
private void goButtonMouseClicked( java.awt.event.MouseEvent evt ) {
errorStub = new StringBuilder();
smallFile = new File( smallFileTextField.getText() );
smallFileTextField.setText( smallFile.getAbsolutePath() );
largeFile = new File( largeFileTextField.getText() );
largeFileTextField.setText( largeFile.getAbsolutePath() );
outputFile = new File( outputFileTextField.getText() );
outputFileTextField.setText( outputFile.getAbsolutePath() );
process();
}
private void setSelectedFile( FILE_TYPES fileType ) {
int returnVal = fileChooser.showOpenDialog( null );
if( returnVal == JFileChooser.APPROVE_OPTION ) {
File file = fileChooser.getSelectedFile();
switch( fileType ) {
case SMALL:
smallFileTextField.setText( file.getPath() );
break;
case LARGE:
largeFileTextField.setText( file.getPath() );
break;
case OUTPUT:
outputFileTextField.setText( file.getPath() );
break;
}
}
}
private void process() {
ArrayList<String> smallFileLines = readFileLines( smallFile );
ArrayList<String> largeFileLines = readFileLines( largeFile );
ArrayList<String> outputFileLines = new ArrayList<String>();
for( String line : smallFileLines ) {
if( !largeFileLines.contains( line ) ) {
outputFileLines.add( line );
} else {
largeFileLines.remove( line );
}
}
if( errorStub.length() == 0 ) {
writeOutput( outputFileLines );
}
if( errorStub.length() == 0 ) {
JOptionPane.showMessageDialog( null, "Finished Successfully!" );
} else {
JOptionPane.showMessageDialog( null, errorStub.toString() );
}
}
private ArrayList<String> readFileLines( File file ) {
ArrayList<String> al = new ArrayList<String>();
try {
FileReader fr = new FileReader( file );
BufferedReader bufRdr = new BufferedReader( fr );
String line = null;
while( ( line = bufRdr.readLine() ) != null ) {
al.add( line );
}
bufRdr.close();
} catch( IOException ioex ) {
errorStub.append( String.format( "Error reading file %s\r\n", file.getAbsolutePath() ) );
System.err.println( ioex.getMessage() );
}
return al;
}
private void writeOutput( ArrayList<String> outputFileLines ) {
try {
FileWriter fw = new FileWriter( outputFile );
BufferedWriter bw = new BufferedWriter( fw );
for( int i = 0; i < outputFileLines.size(); i++ ) {
String line = String.format( "%s%s", outputFileLines.get( i ), i + 1 == outputFileLines.size() ? "" : "\r\n" );
bw.write( line );
}
bw.close();
} catch( Exception ex ) {
errorStub.append( String.format( "Error writing file %s\r\n", outputFile.getAbsolutePath() ) );
System.err.println( ex.getMessage() );
}
}
public static void main( String args[] ) {
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( FileLineComparator.class.getName() ).log( java.util.logging.Level.SEVERE, null, ex );
} catch( InstantiationException ex ) {
java.util.logging.Logger.getLogger( FileLineComparator.class.getName() ).log( java.util.logging.Level.SEVERE, null, ex );
} catch( IllegalAccessException ex ) {
java.util.logging.Logger.getLogger( FileLineComparator.class.getName() ).log( java.util.logging.Level.SEVERE, null, ex );
} catch( javax.swing.UnsupportedLookAndFeelException ex ) {
java.util.logging.Logger.getLogger( FileLineComparator.class.getName() ).log( java.util.logging.Level.SEVERE, null, ex );
}
java.awt.EventQueue.invokeLater( new Runnable() {
public void run() {
new FileLineComparator().setVisible( true );
}
} );
}
private enum FILE_TYPES {
SMALL,
LARGE,
OUTPUT
}
private File smallFile = null;
private File largeFile = null;
private File outputFile = null;
private StringBuilder errorStub = null;
// Variables declaration - do not modify
private javax.swing.JFileChooser fileChooser;
private javax.swing.JButton goButton;
private javax.swing.JButton largeFileButton;
private javax.swing.JLabel largeFileLabel;
private javax.swing.JTextField largeFileTextField;
private javax.swing.JButton outputFileButton;
private javax.swing.JLabel outputFileLabel;
private javax.swing.JTextField outputFileTextField;
private javax.swing.JButton smallFileButton;
private javax.swing.JLabel smallFileLabel;
private javax.swing.JTextField smallFileTextField;
// End of variables declaration
}