文件的读写代码块(二)
来源:互联网 发布:php 开源社区系统 编辑:程序博客网 时间:2024/06/05 18:02
public class FileTest { //定义一个文件 private static File file=new File("C://Users//Administrator//Desktop//helloSpark.txt"); public static void writeData(){ InputStream in=null; OutputStream out=null; try { in=new FileInputStream(file); out=new FileOutputStream(file); int len=-1; byte buffer[]=new byte[1024]; while((len=in.read(buffer))!=-1){ out.write(buffer, 0, len); } System.out.println("写入数据完成了..."); } catch (Exception e) { e.printStackTrace(); }finally{ try { in.close(); out.close(); } catch (Exception e) { e.printStackTrace(); } } } public static void readData(){ InputStream in=null; try { in=new FileInputStream(file); int len=-1; byte buffer[]=new byte[1024]; while((len=in.read(buffer))!=-1){ System.out.println(new String(buffer)); } System.out.println("读取数据完成了..."); } catch (Exception e) { e.printStackTrace(); }finally{ try { in.close(); } catch (Exception e) { e.printStackTrace(); } } } public static void main(String[] args) {// writeData(); readData(); }
阅读全文
0 0
- 文件的读写代码块(二)
- MyEclipse/Eclipse 创建模板代码/文件读写代码块
- 读写文件的代码
- 读写配置文件代码块
- 以数据块的形式读写文件
- 111,文件的读写(二)
- JPEG文件的读写(二)
- sqlplus执行代码块 包含代码块的sql文件
- java的代码块优先级 (静态代码块,构造代码块,普通代码块)
- Java读写文件(二)
- 字符、字符串(行)、块(文件)读写文件流
- IOS Block 代码块使用 (二)
- iOS开发常用代码块(二)
- Java进阶教程(二)代码块
- 代码块开发二
- 静态代码块(二)
- 利用C++文件流进行数据块的读写
- C语言以数据块的形式读写文件
- git与svn的差异
- java8 时间/日期 localDateTime比较,获取年月日时分秒
- java 中Map 常用的子类 之 TreeMap
- 线上服务内存OOM问题定位三板斧
- 一只爬虫带你看世界【1】
- 文件的读写代码块(二)
- 习题三3.2
- 10.23刷题记录
- 100019. 【NOI2017模拟6.26】A
- Java反射机制
- 为什么在java中不能创建泛型数组
- html上传文件
- 【安全牛学习笔记】CSRF跨站请求伪造攻击漏洞的原理及解决办法
- LeetCode Add Two Numbers