Java BufferedReader Read readFileEncoding(String file)

Here you can find the source of readFileEncoding(String file)

Description

read File Encoding

License

Open Source License

Declaration

public static String readFileEncoding(String file) 

Method Source Code

//package com.java2s;
/* gvSIG. Sistema de Informaci?n Geogr?fica de la Generalitat Valenciana
 *
 * Copyright (C) 2008 IVER T.I. and Generalitat Valenciana.
 *
 * This program is free software; you can redistribute it and/or
 * modify it under the terms of the GNU General Public License
 * as published by the Free Software Foundation; either version 2
 * of the License, or (at your option) any later version.
 *
 * This program is distributed in the hope that it will be useful,
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
 * GNU General Public License for more details.
 *
 * You should have received a copy of the GNU General Public License
 * along with this program; if not, write to the Free Software
 * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA  02111-1307,USA.
 *//*  w  w  w  . j  a v  a2 s.c  om*/

import java.io.BufferedReader;

import java.io.FileNotFoundException;

import java.io.FileReader;
import java.io.IOException;

public class Main {

    public static String readFileEncoding(String file) {
        FileReader fr;
        String encoding = null;
        try {
            fr = new FileReader(file);
            BufferedReader br = new BufferedReader(fr);
            char[] buffer = new char[100];
            br.read(buffer);
            StringBuffer st = new StringBuffer(new String(buffer));
            String searchText = "encoding=\"";
            int index = st.indexOf(searchText);
            if (index > -1) {
                st.delete(0, index + searchText.length());
                encoding = st.substring(0, st.indexOf("\""));
            }
            fr.close();
        } catch (FileNotFoundException ex) {
            ex.printStackTrace();
        } catch (IOException e) {
            e.printStackTrace();
        }
        return encoding;
    }
}

Related

  1. readFileAsListOfStrings(String filename)
  2. readFileAsListOfStrings(String filename)
  3. readFileAsText(String path)
  4. readFileByChar(String path)
  5. readFileContext(File fileToRead)
  6. readFileGdeHash(File gdeFile, ArrayList name, ArrayList seq)
  7. readFilePathToString(String filePath)
  8. readFileToHashMap(String filePath, String separator, boolean valueFirst)
  9. readFileToHashMap(String filePath, String separator, boolean valueFirst)