Answers for "how to know if a file is iso-8859-1 encoded in java"

0

how to know if a file is iso-8859-1 encoded in java

FileInputStream fIn  = new FileInputStream(myFile);
            byte[] buf = new byte[4096];
            UniversalDetector detector = new UniversalDetector(null);
            int nread;
            while ((nread = fIn.read(buf)) > 0 && !detector.isDone()) {
                detector.handleData(buf, 0, nread);
            }
            detector.dataEnd();
            String encoding = detector.getDetectedCharset();
            String chartsetName = null;
            if (encoding.equalsIgnoreCase("WINDOWS-1252")){
                chartsetName = "ISO-8859-1";
            }
            if (encoding.equalsIgnoreCase("UTF-8")){
                chartsetName = "UTF-8";
            }

            BufferedReader myReader = new BufferedReader(new InputStreamReader(fIn, chartsetName));
Posted by: Guest on July-08-2020

Code answers related to "how to know if a file is iso-8859-1 encoded in java"

Code answers related to "Java"

Java Answers by Framework

Browse Popular Code Answers by Language