Android 读取txt文档
来源:互联网 发布:mathlab mac版怎么样 编辑:程序博客网 时间:2024/04/28 07:51
Android 读取txt文档
<pre name="code" class="java">/*** * 将文本文件中的内容读成字符串 * ***/private String getTextString(String pathandname, String code) {String str = "";try {FileInputStream fis = new FileInputStream(pathandname);int size = fis.available();byte[] buffer = new byte[size];fis.read(buffer);fis.close();str = new String(buffer, code);} catch (FileNotFoundException e) {// TODO Auto-generated catch blocke.printStackTrace();} catch (UnsupportedEncodingException e) {// TODO Auto-generated catch blocke.printStackTrace();} catch (IOException e) {// TODO Auto-generated catch blocke.printStackTrace();}return str;}/**** * 无法确切的判断出文档的编码是gbk或者是gb2312 获取指定文档的编码方式 * ***/public static String getCode(String filepath) {File file = new File(filepath);System.out.println(file.exists() + "," + file.getAbsolutePath());String code = "";try {FileInputStream fis = new FileInputStream(file);BufferedInputStream in = new BufferedInputStream(fis);in.mark(4);byte[] first3bytes = new byte[3];in.read(first3bytes);// 找到文档的前三个字节并自动判断文档类型。in.reset();if (first3bytes[0] == (byte) 0xEF && first3bytes[1] == (byte) 0xBB&& first3bytes[2] == (byte) 0xBF) {// utf-8code = "utf-8";} else if (first3bytes[0] == (byte) 0xFF&& first3bytes[1] == (byte) 0xFE) {code = "unicode";} else if (first3bytes[0] == (byte) 0xFE&& first3bytes[1] == (byte) 0xFF) {code = "utf-16be";} else if (first3bytes[0] == (byte) 0xFF&& first3bytes[1] == (byte) 0xFF) {code = "utf-16le";} else {// 无法确切判断出gb2312的编码code = "GB2312";code = "utf-8";}in.close();} catch (FileNotFoundException e) {// TODO Auto-generated catch blocke.printStackTrace();} catch (UnsupportedEncodingException e) {// TODO Auto-generated catch blocke.printStackTrace();} catch (IOException e) {// TODO Auto-generated catch blocke.printStackTrace();}return code;}
0 0
- Android 读取txt文档
- Android大TXT文本文档读取
- matlab txt文档读取
- java读取txt文档
- TXT文档读取
- java读取txt文档
- 读取txt文档
- C读取txt文档
- 读取txt文档创建位图
- 读取txt文档并分页
- 使用oledb读取txt文档
- 读取txt文档并分页
- JavaScript 读取、写入Txt文档
- JavaScript 读取、写入Txt文档
- matlab读取txt文档行数
- 文档解析之txt文档的读取
- android 读取TXT文件
- android 读取txt文件
- 希尔排序
- 适用于2G/3G/4G的无线终端基带芯片
- spring+spring mvc+mybatis+mysql+easyui实现的分页
- 兹棕灼佐尊座咨租住准邹走琢揍坠纵孜琢
- Java多线程--让主线程等待所有子线程执行完毕
- Android 读取txt文档
- 树的左旋与右旋
- 安卓错误Failed to fetch URL https://dl-ssl.google.com/android/repository/addons_list.xml
- 一些实用的tunning SQL时用到的Showplan SET Options
- 直接选择排序 (异或swap两个数存在陷阱)
- ReadConsoleInputA no longer works correctly with DBCS in Windows 8.1
- 阻桌仔浊综总捉妆状揍转庄滓撞孜钻拙尊
- 归并排序
- 安卓开发遇到的一些非代码问题