Search
 
SCRIPT & CODE EXAMPLE
 

JAVA

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));
Comment

PREVIOUS NEXT
Code Example
Java :: check if LinkedList is empyth java 
Java :: create an empty array in java 
Java :: reader from string java 
Java :: java gmt zoneid 
Java :: netbeans android sdk location 
Java :: java make object 
Java :: difference between getcontext and getapplicationcontext in android 
Java :: java set file folder permissions 
Java :: Java Program to Change the Border of a JFrame: 
Java :: put arraylist in hashtable java 
Java :: could not load main class java 
Java :: has been compiled by a more recent version of the Java Runtime (class file version 55.0) 
Java :: switch en java 
Java :: initialize an arraylist in java in java 
Java :: How to efficiently find the diameter of a binary tree, in Java? 
Java :: my maven project give error when adding javax.xml.bind dependency 
Java :: how to sort the arraylist without changing the original arraylist 
Java :: java swing draw centered text 
Java :: fibonacci of 6 
Java :: Create Java Strings using the new keyword 
Java :: How to change integers into float in java 
Java :: Java peek() Method 
Java :: convert alphabet to number in java 
Java :: java parameterized constructor 
Java :: java to c# converter 
Java :: java compile 
Java :: convert json to xml in java 
Java :: basics of java 
Java :: private access modifiers 
Java :: generics Interface in java 
ADD CONTENT
Topic
Content
Source link
Name
3+1 =