`
annewman
  • 浏览: 30123 次
  • 性别: Icon_minigender_1
  • 来自: 深圳
社区版块
存档分类
最新评论

JAVA程序获取文件格式

    博客分类:
  • File
阅读更多
import info.monitorenter.cpdetector.io.CodepageDetectorProxy;
import info.monitorenter.cpdetector.io.JChardetFacade;

import java.io.File;
import java.nio.charset.Charset;

public class CharacterEnding {

	public static String getFileCharacterEnding(String filePath) {
		File file = new File(filePath);
		return getFileCharacterEnding(file);
	}
	public static String getFileCharacterEnding(File file) {

		String fileCharacterEnding = "1 =";

		CodepageDetectorProxy detector = CodepageDetectorProxy.getInstance();
		detector.add(JChardetFacade.getInstance());

		Charset charset = null;

		try {
			charset = detector.detectCodepage(file.toURL());
		} catch (Exception e) {
			e.printStackTrace();
		}
		if (charset != null) {
			fileCharacterEnding = charset.name();
		}

		return fileCharacterEnding;
	}
}

 

分享到:
评论

相关推荐

Global site tag (gtag.js) - Google Analytics