Untitled

 avatar
unknown
plain_text
2 years ago
1.4 kB
4
Indexable
import java.io.BufferedReader;
import java.io.BufferedWriter;
import java.io.FileReader;
import java.io.FileWriter;
import java.io.IOException;

public class ProcessFile {

    public static void main(String[] args) {
        if (args.length != 2) {
            System.out.println("Sử dụng: java ProcessFile input_file output_file");
            System.exit(1);
        }

        String inputFile = args[0];
        String outputFile = args[1];

        try (BufferedReader reader = new BufferedReader(new FileReader(inputFile));
             BufferedWriter writer = new BufferedWriter(new FileWriter(outputFile))) {

            String line;
            while ((line = reader.readLine()) != null) {
                // Lấy các phần tử A, B, C, D từ dòng hiện tại
                String[] parts = line.split(".android|\\.test|@", -1);
                if (parts.length == 4) {
                    String A = parts[0];
                    String B = parts[1];
                    String C = parts[2];
                    String D = parts[3];

                    // Ghi kết quả vào file đầu ra
                    writer.write(String.format("%s %s %s#%s%n", D, A, B, C));
                }
            }

            System.out.println("Quá trình hoàn tất. Kết quả được ghi vào " + outputFile);

        } catch (IOException e) {
            e.printStackTrace();
        }
    }
}
Editor is loading...
Leave a Comment