You can do this with CharsetEncoder. You should read the "native" text with the correct encoding in unicode. How can you use the "US-ASCII" encoder to detect which characters should be translated in unicode escape sequences.
import java.nio.charset.Charset; import java.nio.charset.CharsetEncoder; import org.junit.Test; public class EncodeToEscapes { @Test public void testEncoding() { final String src = "Hallo äöü";
In addition, org.apache.commons: commons-lang contains StringEscapeUtils.escapeJava (), which can hide and undo native lines.
source share