解析txt文件数据
来源:互联网 发布:航天开盘软件 编辑:程序博客网 时间:2024/05/16 12:40
- public class FileAccess extends Activity {
- /**
- * 一、私有文件夹下的文件存取(/data/data/包名/files)
- *
- * @param fileName
- * @param message
- */
- public void writeFileData(String fileName, String message) {
- try {
- FileOutputStream fout = openFileOutput(fileName, MODE_PRIVATE);
- byte[] bytes = message.getBytes();
- fout.write(bytes);
- fout.close();
- } catch (Exception e) {
- e.printStackTrace();
- }
- }
- /**
- * //读文件在./data/data/包名/files/下面
- *
- * @param fileName
- * @return
- */
- public String readFileData(String fileName) {
- String res = "";
- try {
- FileInputStream fin = openFileInput(fileName);
- int length = fin.available();
- byte[] buffer = new byte[length];
- fin.read(buffer);
- res = EncodingUtils.getString(buffer, "UTF-8");
- fin.close();
- } catch (Exception e) {
- e.printStackTrace();
- }
- return res;
- }
- /**
- * 写, 读sdcard目录上的文件,要用FileOutputStream, 不能用openFileOutput
- * 不同点:openFileOutput是在raw里编译过的,FileOutputStream是任何文件都可以
- * @param fileName
- * @param message
- */
- // 写在/mnt/sdcard/目录下面的文件
- public void writeFileSdcard(String fileName, String message) {
- try {
- // FileOutputStream fout = openFileOutput(fileName, MODE_PRIVATE);
- FileOutputStream fout = new FileOutputStream(fileName);
- byte[] bytes = message.getBytes();
- fout.write(bytes);
- fout.close();
- }
- catch (Exception e) {
- e.printStackTrace();
- }
- }
- // 读在/mnt/sdcard/目录下面的文件
- public String readFileSdcard(String fileName) {
- String res = "";
- try {
- FileInputStream fin = new FileInputStream(fileName);
- int length = fin.available();
- byte[] buffer = new byte[length];
- fin.read(buffer);
- res = EncodingUtils.getString(buffer, "UTF-8");
- fin.close();
- }
- catch (Exception e) {
- e.printStackTrace();
- }
- return res;
- }
- /**
- * 二、从resource中的raw文件夹中获取文件并读取数据(资源文件只能读不能写)
- *
- * @param fileInRaw
- * @return
- */
- public String readFromRaw(int fileInRaw) {
- String res = "";
- try {
- InputStream in = getResources().openRawResource(fileInRaw);
- int length = in.available();
- byte[] buffer = new byte[length];
- in.read(buffer);
- res = EncodingUtils.getString(buffer, "GBK");
- // res = new String(buffer,"GBK");
- in.close();
- } catch (Exception e) {
- e.printStackTrace();
- }
- return res;
- }
- /**
- * 三、从asset中获取文件并读取数据(资源文件只能读不能写)
- *
- * @param fileName
- * @return
- */
- public String readFromAsset(String fileName) {
- String res = "";
- try {
- InputStream in = getResources().getAssets().open(fileName);
- int length = in.available();
- byte[] buffer = new byte[length];
- in.read(buffer);
- res = EncodingUtils.getString(buffer, "UTF-8");
- } catch (Exception e) {
- e.printStackTrace();
- }
- return res;
- }
阅读全文
0 0
- 解析txt文件数据
- java解析txt文件
- 解析TXT文件
- 解析TXT文件2
- 解析txt文件
- java解析txt文件
- 解析.txt文件入库
- Java解析txt文件
- 通过Http地址返回JSON数据,进行解析;通过ftp返回.txt文件数据,进行解析;
- unity中从txt文件中读取解析json数据&&unity中json数据写入txt文件
- 文件解析(Java 解析 txt 文件)
- 解析Txt文件的过程
- java 解析txt,conf 文件
- 生成和解析txt文件
- 解析.txt文件的方法
- TXT文件编码格式解析
- 用RegExp解析TXT文件
- txt文件解析简易框架
- C/C++连接mysql编译的找不到mysql/mysql.h的问题
- 【转载】PHP register_shutdown_function函数详解
- makfile中.PHONY的认识【转】
- 【转载】解决ncurses中文乱码问题
- [php] 索引数组合并选择两数组相加
- 解析txt文件数据
- 如何配置XAMPP的虚拟主机[转]
- 为XAMPP添加MemCache支持【转】
- Vue--缩写
- Sysctl [摘]
- <meta http-equiv=\"refresh\" content=\"0; url=\"> 【转】
- C语言——内存管理
- SVN操作
- LINUX命令行 查看memcache运行状态