I need to programatically change the encoding of a set of *nix scripts to UTF-8 from Java. I won't write anything to them, so I'm trying to find what's the easiest|fastest way to do this. The files are not too many and are not that big. I could:
Not a big deal, but has anyone run into this case before? Are there any cons on either approach?
As requested, and since you're using commons io, here is example code (error checking to the wind):
import java.io.File;
import java.io.IOException;
import org.apache.commons.io.FileUtils;
public class Main {
public static void main(String[] args) throws IOException {
String filename = args[0];
File file = new File(filename);
String content = FileUtils.readFileToString(file, "ISO8859_1");
FileUtils.write(file, content, "UTF-8");
}
}
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With