设为首页 加入收藏

TOP

Android中读取中文字符的文件与文件读取相关(二)
2014-11-24 03:20:02 来源: 作者: 【 】 浏览:4
Tags:Android 读取 中文 字符 文件 相关
read(bytes);


str = EncodingUtils.getString(bytes,"UTF-8");


fin.close();


}


catch(Exception e){


e.printStackTrace();


}


return str;


}


(4) sdcard目录下的文件存取(/mnt/sdcard/)


使用FileOutputStream写文件:


public void writeFile2Sdcard(String fileName,String message){


try{


FileOutputStream fout = new FileOutputStream(fileName);


byte [] bytes =message.getBytes();


fout.write(bytes);


fout.close();


}


catch(Exception e){


e.printStackTrace();


}


}


使用FileInputStream读文件:


public String readFileFromSdcard(String fileName){


String res="";


try{


FileInputStream fin = newFileInputStream(fileName);


int length =fin.available();


byte [] buffer = newbyte[length];


fin.read(buffer);


res =EncodingUtils.getString(buffer, "UTF-8");


fin.close();


}


catch(Exception e){


e.printStackTrace();


}


return res;


}


首页 上一页 1 2 下一页 尾页 2/2/2
】【打印繁体】【投稿】【收藏】 【推荐】【举报】【评论】 【关闭】 【返回顶部
分享到: 
上一篇Android 用自定义PopupWindow实现.. 下一篇Android控件倒计时的实现

评论

帐  号: 密码: (新用户注册)
验 证 码:
表  情:
内  容:

·常用meta整理 | 菜鸟 (2025-12-25 01:21:52)
·SQL HAVING 子句:深 (2025-12-25 01:21:47)
·SQL CREATE INDEX 语 (2025-12-25 01:21:45)
·Shell 传递参数 (2025-12-25 00:50:45)
·Linux echo 命令 - (2025-12-25 00:50:43)