UTF-8 HTML and CSS files with BOM (and how to remove the BOM with Python)

Since you state: All of my (text) files are currently stored in UTF-8 with the BOM then use the ‘utf-8-sig’ codec to decode them: >>> s = u’Hello, world!’.encode(‘utf-8-sig’) >>> s ‘\xef\xbb\xbfHello, world!’ >>> s.decode(‘utf-8-sig’) u’Hello, world!’ It automatically removes the expected BOM, and works correctly if the BOM is not present as well.

Character encoding JSP -displayed wrong in JSP but not in URL: “á » á é » é”

Try to set URIEncoding in {jboss.server}/deploy/jboss-web.deployer/server.xml. Ex: <Connector port=”8080″ address=”${jboss.bind.address}” maxThreads=”250″ maxHttpHeaderSize=”8192″ emptySessionPath=”true” protocol=”HTTP/1.1″ enableLookups=”false” redirectPort=”8443″ acceptCount=”100″ connectionTimeout=”20000″ disableUploadTimeout=”true” URIEncoding=”UTF-8″ />

How to read UTF8 encoded file using RandomAccessFile?

You can convert string, read by readLine to UTF8, using following code: public static void main(String[] args) throws IOException { RandomAccessFile raf = new RandomAccessFile(new File(“MyFile.txt”), “r”); String line = raf.readLine(); String utf8 = new String(line.getBytes(“ISO-8859-1”), “UTF-8”); System.out.println(“Line: ” + line); System.out.println(“UTF8: ” + utf8); } Content of MyFile.txt: (UTF-8 Encoding) Привет из Украины Console … Read more

UTF-8 in PHP regular expressions [duplicate]

Updated answer: This is now tested and working $post=”9999, škofja loka”; echo preg_match(‘/^\\d{4},[\\s\\p{L}]+$/u’, $post); \\w will not work, because it does not contain all unicode letters and contains also [0-9_] additionally to the letters. Important is also the u modifier to activate the unicode mode. If there can be letters or whitespace after the comma … Read more

Java Encode file to Base64 string To match with other encoded string

You already using apache commons-codec so I recommend adding commons-io for reading the file. That way you can remove your loadFile() method and just have: private static String encodeFileToBase64Binary(String fileName) throws IOException { File file = new File(fileName); byte[] encoded = Base64.encodeBase64(FileUtils.readFileToByteArray(file)); return new String(encoded, StandardCharsets.US_ASCII); }