All Downloads are FREE. Search and download functionalities are using the official Maven repository.

org.bdware.datanet.JavaSed Maven / Gradle / Ivy

There is a newer version: 0.6.9
Show newest version
package org.bdware.datanet;

import java.io.File;
import java.io.FileInputStream;
import java.io.FileOutputStream;
import java.nio.charset.StandardCharsets;

public class JavaSed {
    public static void replace(String inputFile, String outputFile, String regex, String replacement) {
        try {
            File file = new File(inputFile);
            byte[] content = new byte[(int) file.length()];
            FileInputStream fin = new FileInputStream(inputFile);
            fin.read(content);
            String str = new String(content);
            str = str.replaceAll(regex, replacement);
            fin.close();
            FileOutputStream fout = new FileOutputStream(outputFile);
            fout.write(str.getBytes(StandardCharsets.UTF_8));
            fout.close();
        } catch (Exception e) {
            e.printStackTrace();
        }

    }
}




© 2015 - 2025 Weber Informatics LLC | Privacy Policy