Android 读取TXT 文件中文乱码 解决方案
16lz
2021-01-23
/********** Android 读取文件 中文 转码 ********/
BufferedReader bufferedReader = null;if (fileName.equals("/DoctorRecodeIOS.txt")) //文件默认编码为ANSI bufferedReader = new BufferedReader(new InputStreamReader(new FileInputStream(downLoadFile), "GB2312"));else if (fileName.equals("/patientRecodeIOS.txt")) //文件默认为utf-8 bufferedReader = new BufferedReader(new InputStreamReader(new FileInputStream(downLoadFile), "utf-8"));
/*************2. 读取文件内容保存至fileContent***************/ while ((strReadLine = bufferedReader.readLine()) != null) {/* String temp1 = EncodingUtils.getString(strReadLine.getBytes(),"GB2312"); String temp2 = EncodingUtils.getString(strReadLine.getBytes("utf-8"),"utf-8"); String temp3 = EncodingUtils.getString(strReadLine.getBytes(),"utf-8");*/ stringBuffer.append(strReadLine + "\n"); fileContent = new String(stringBuffer); }
//如果不识别
EncodingUtils
builde gradule 中添加
dependencies { compile fileTree(dir: 'libs', include: ['*.jar']) androidTestCompile('com.android.support.test.espresso:espresso-core:2.2.2', { exclude group: 'com.android.support', module: 'support-annotations' }) compile 'com.android.support:appcompat-v7:25.3.1' compile 'org.apache.httpcomponents:httpcore:4.4.4' //识别 EncodingUtils testCompile 'junit:junit:4.12'}
更多相关文章
- android:获取网络时间、文件路径,修改包名,发布release版本
- Android文件列表RecyclerView中点击视频播放
- Android Dex文件结构
- android 文件存储注意点
- Android的动画配置xml文件
- android 打开文件
- Android--用SAX解析xml文件
- Android复制文件