Android/java 读写文件
来源:互联网 发布:python getattr 函数 编辑:程序博客网 时间:2024/05/17 20:10
读内存卡的文件
读取图片,视频等媒体文件byte流,
public static byte[] readStream(String imagepath) throws Exception {FileInputStream fs = new FileInputStream(imagepath);ByteArrayOutputStream outStream = new ByteArrayOutputStream();byte[] buffer = new byte[1024];int len = 0;while (-1 != (len = fs.read(buffer))) {outStream.write(buffer, 0, len);}outStream.close();fs.close();return outStream.toByteArray();}
读取文本文件,用Strng保存
public String readFile(String filename){ String content = null; File file = new File(filename); //for ex foo.txt try { FileReader reader = new FileReader(file); char[] chars = new char[(int) file.length()]; reader.read(chars); content = new String(chars); reader.close(); } catch (IOException e) { e.printStackTrace(); } return content;}
public void writeFile(String filePath,byte[] f){try {FileOutputStream out = new FileOutputStream(new File(filePath));out.write(f);out.close();} catch (IOException e) {e.printStackTrace();} }
public void writeFile(String filePath,String f){FileWriter fw;try {fw = new FileWriter(filePath);fw.write(f);fw.close();} catch (IOException e) {e.printStackTrace();} }
1 0
- Android/java 读写文件
- Android Java 如何读写XML文件
- Java与Android的文件读写操作
- Java Android 创建读写TXT文件
- 【android】:android文件读写
- Android读写文件基于Java的文件输入输出流
- android文件读写,ndk文件读写
- Android下 读写文件
- android 读写文件
- Android文件的读写
- Android 文件读写
- android 读写文件
- Android读写文件
- Android下读写文件
- Android文件的读写
- Android读写文件
- android读写文件
- Android读写文件
- Ajax工作原理
- clojure source code
- 实战Mahout聚类算法Canopy+K-means
- 九度OJ 1437 To Fill or Not to Fill -- 贪心算法
- 关于正则表达式
- Android/java 读写文件
- MSR和MRS 指令
- VC MFC 调整 TAb键序
- STL学习笔记1 List
- 大蛇继续
- 九度OJ 1468 Sharing -- 哈希
- 小强的HTML5移动开发之路(34)——jQuery中的选择器
- 基于BOLT的仿迅雷加速器界面开发(二)
- Xcode5 运行程序 提示“iOS 模拟器”未能安装此应用程序