package systems.crigges.kamil;
 
import java.awt.EventQueue;
 
import javax.swing.JFrame;
import javax.swing.GroupLayout;
import javax.swing.GroupLayout.Alignment;
import javax.swing.JButton;
import javax.swing.JFileChooser;
import javax.swing.JTextField;
import javax.swing.LayoutStyle.ComponentPlacement;
import javax.swing.UIManager;
import javax.swing.UnsupportedLookAndFeelException;
import javax.swing.JLabel;
import javax.swing.JTextArea;
import javax.swing.border.LineBorder;
import javax.swing.plaf.FileChooserUI;
 
import java.awt.Color;
import java.awt.event.ActionListener;
import java.io.File;
import java.io.FileOutputStream;
import java.nio.file.Files;
import java.awt.event.ActionEvent;
 
public class Kamil {
 
    private JFrame frame;
    private JTextField textField;
    private JTextField textField_1;
    private JTextField textField_2;
 
    /**
     * Launch the application.
     * @throws UnsupportedLookAndFeelException
     * @throws IllegalAccessException
     * @throws InstantiationException
     * @throws ClassNotFoundException
     */
    public static void main(String[] args) throws ClassNotFoundException, InstantiationException, IllegalAccessException, UnsupportedLookAndFeelException {
        UIManager.setLookAndFeel(UIManager.getSystemLookAndFeelClassName());
        EventQueue.invokeLater(new Runnable() {
            public void run() {
                try {
                    Kamil window = new Kamil();
                    window.frame.setVisible(true);
                } catch (Exception e) {
                    e.printStackTrace();
                }
            }
        });
    }
 
    /**
     * Create the application.
     */
    public Kamil() {
        initialize();
    }
 
    /**
     * Initialize the contents of the frame.
     */
    private void initialize() {
        frame = new JFrame();
        frame.setBounds(100, 100, 729, 354);
        frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
 
        JButton btnSelect = new JButton("Select...");
        btnSelect.addActionListener(new ActionListener() {
            public void actionPerformed(ActionEvent e) {
                JFileChooser fc = new JFileChooser();
                fc.setCurrentDirectory(new File(textField.getText().equals("") ? "." :  textField.getText()));
                fc.setFileSelectionMode(JFileChooser.DIRECTORIES_ONLY);
                fc.setAcceptAllFileFilterUsed(false);
                if (fc.showOpenDialog(frame) == JFileChooser.APPROVE_OPTION) {
                    textField.setText(fc.getSelectedFile().getAbsolutePath());
                }
            }
        });
 
        textField = new JTextField();
        textField.setEditable(false);
        textField.setColumns(10);
 
        JLabel lblSource = new JLabel("Source Folder");
 
        textField_1 = new JTextField();
        textField_1.setEditable(false);
        textField_1.setColumns(10);
 
        JLabel lblDestinationFolder = new JLabel("Destination Folder");
 
        JButton button = new JButton("Select...");
        button.addActionListener(new ActionListener() {
            public void actionPerformed(ActionEvent e) {
                JFileChooser fc = new JFileChooser();
                fc.setCurrentDirectory(new File(textField_1.getText().equals("") ? "." : textField_1.getText() ));
                fc.setFileSelectionMode(JFileChooser.DIRECTORIES_ONLY);
                fc.setAcceptAllFileFilterUsed(false);
                if (fc.showOpenDialog(frame) == JFileChooser.APPROVE_OPTION) {
                    textField_1.setText(fc.getSelectedFile().getAbsolutePath());
                }
            }
        });
 
        JButton btnNewButton = new JButton("Process");
        btnNewButton.addActionListener(new ActionListener() {
            public void actionPerformed(ActionEvent e) {
                try{
                    File sourceFolder = new File(textField.getText());
                    File[] files = sourceFolder.listFiles();
                    for(File f : files){
                        String content = new String(Files.readAllBytes(f.toPath()));
                        int index = content.lastIndexOf(";$ZYKART_ENDE");
                        String before = content.substring(0, index);
                        String after = content.substring(index);
                        String res = before + ";$ZYKLUS_ENDE\r\n" + after;
                        FileOutputStream out = new FileOutputStream(new File(textField_1.getText() + "\\" + f.getName()));
                        out.write(res.getBytes());
                        out.close();
                        if(!textField_2.getText().equals("")){
                            out = new FileOutputStream(new File(textField_2.getText() + "\\" + f.getName()));
                            out.write(res.getBytes());
                            out.close();
                        }
                        f.delete();
                    }
                }catch(Exception ec){
                    ec.printStackTrace();;
                }
            }
        });
 
        JLabel lblDestinationFolder_1 = new JLabel("Destination Folder 2");
 
        textField_2 = new JTextField();
        textField_2.setEditable(false);
        textField_2.setColumns(10);
 
        JButton button_1 = new JButton("Select...");
        button_1.addActionListener(new ActionListener() {
            public void actionPerformed(ActionEvent e) {
                JFileChooser fc = new JFileChooser();
                fc.setCurrentDirectory(new File(textField_2.getText().equals("") ? "." : textField_2.getText() ));
                fc.setFileSelectionMode(JFileChooser.DIRECTORIES_ONLY);
                fc.setAcceptAllFileFilterUsed(false);
                if (fc.showOpenDialog(frame) == JFileChooser.APPROVE_OPTION) {
                    textField_2.setText(fc.getSelectedFile().getAbsolutePath());
                }
            }
        });
        GroupLayout groupLayout = new GroupLayout(frame.getContentPane());
        groupLayout.setHorizontalGroup(
            groupLayout.createParallelGroup(Alignment.TRAILING)
                .addGroup(groupLayout.createSequentialGroup()
                    .addContainerGap()
                    .addGroup(groupLayout.createParallelGroup(Alignment.LEADING)
                        .addComponent(lblSource)
                        .addComponent(btnNewButton, Alignment.TRAILING, GroupLayout.PREFERRED_SIZE, 143, GroupLayout.PREFERRED_SIZE)
                        .addGroup(Alignment.TRAILING, groupLayout.createSequentialGroup()
                            .addGroup(groupLayout.createParallelGroup(Alignment.LEADING)
                                .addComponent(textField_1, GroupLayout.DEFAULT_SIZE, 493, Short.MAX_VALUE)
                                .addComponent(textField, Alignment.TRAILING, GroupLayout.DEFAULT_SIZE, 493, Short.MAX_VALUE))
                            .addPreferredGap(ComponentPlacement.RELATED)
                            .addGroup(groupLayout.createParallelGroup(Alignment.LEADING, false)
                                .addComponent(btnSelect, GroupLayout.DEFAULT_SIZE, GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)
                                .addComponent(button, GroupLayout.DEFAULT_SIZE, 101, Short.MAX_VALUE)))
                        .addGroup(Alignment.TRAILING, groupLayout.createSequentialGroup()
                            .addComponent(textField_2, GroupLayout.DEFAULT_SIZE, 567, Short.MAX_VALUE)
                            .addPreferredGap(ComponentPlacement.RELATED)
                            .addComponent(button_1, GroupLayout.PREFERRED_SIZE, 101, GroupLayout.PREFERRED_SIZE))
                        .addComponent(lblDestinationFolder_1, GroupLayout.PREFERRED_SIZE, 182, GroupLayout.PREFERRED_SIZE)
                        .addComponent(lblDestinationFolder, GroupLayout.PREFERRED_SIZE, 182, GroupLayout.PREFERRED_SIZE))
                    .addContainerGap())
        );
        groupLayout.setVerticalGroup(
            groupLayout.createParallelGroup(Alignment.LEADING)
                .addGroup(groupLayout.createSequentialGroup()
                    .addContainerGap()
                    .addComponent(lblSource)
                    .addPreferredGap(ComponentPlacement.RELATED)
                    .addGroup(groupLayout.createParallelGroup(Alignment.BASELINE)
                        .addComponent(textField, GroupLayout.PREFERRED_SIZE, GroupLayout.DEFAULT_SIZE, GroupLayout.PREFERRED_SIZE)
                        .addComponent(btnSelect))
                    .addPreferredGap(ComponentPlacement.RELATED)
                    .addComponent(lblDestinationFolder)
                    .addPreferredGap(ComponentPlacement.RELATED)
                    .addGroup(groupLayout.createParallelGroup(Alignment.BASELINE)
                        .addComponent(textField_1, GroupLayout.PREFERRED_SIZE, GroupLayout.DEFAULT_SIZE, GroupLayout.PREFERRED_SIZE)
                        .addComponent(button))
                    .addPreferredGap(ComponentPlacement.RELATED)
                    .addGroup(groupLayout.createParallelGroup(Alignment.TRAILING)
                        .addGroup(groupLayout.createSequentialGroup()
                            .addComponent(lblDestinationFolder_1)
                            .addPreferredGap(ComponentPlacement.RELATED)
                            .addComponent(textField_2, GroupLayout.PREFERRED_SIZE, GroupLayout.DEFAULT_SIZE, GroupLayout.PREFERRED_SIZE))
                        .addComponent(button_1))
                    .addPreferredGap(ComponentPlacement.RELATED, 38, Short.MAX_VALUE)
                    .addComponent(btnNewButton)
                    .addContainerGap())
        );
        frame.getContentPane().setLayout(groupLayout);
    }
}
 

goto line:
Compare with:
text copy window edit this code post new code