朝辞白帝彩云间,千里江陵一日还。
两岸猿声啼不尽,轻舟已过万重山。

              ——早发白帝城

我们老师写代码有个特点,就是简洁。每一句的意图都十分明确。所以他讲课的速度也比较快。

跑题了,说说I/O流:

1、字节输入流

2、字符输入流

3、字节输出流

4、字符输出流

上代码:

 public class FileInputStreamAndFileoutputSteamDemo {

     public static void main(String[] args) throws IOException {
FileOutputStream fos = new FileOutputStream("/home/yanshaochen/public/abc.txt");
byte[] bytes = new byte[];
bytes = "金麟岂是池中物,一遇风云变化龙".getBytes();
fos.write(bytes);
fos.close();
FileInputStream fis = new FileInputStream("/home/yanshaochen/public/abc.txt");
String str = "";
int data;
while ((data = fis.read(bytes)) != -) {
str += new String(bytes, , data);
}
System.out.println(str);
fis.close();
}
}
 public class WriterAndReader {

     public static void main(String[] args) throws IOException {
String path = "/home/yanshaochen/public/abc.txt";
Writer wt = new FileWriter(path);
String str = "AAAAA";
wt.write(str);
wt.close();
Reader rd = new FileReader(path);
char[] chars = new char[];
int data;
str = "";
while ((data = rd.read(chars))!=-) {
str += new String(chars, , data);
}
System.out.println(str);
rd.close();
}
}

带缓冲区的字符输入输出流

 public class BufferedReaderAndBufferedWriter {

     public static void main(String[] args) throws IOException {
Writer fw = new FileWriter("/home/yanshaochen/public/abc.txt");
BufferedWriter bw = new BufferedWriter(fw);
String str = "AAAAAAAA";
bw.write(str);
bw.newLine();
bw.close();
Reader fr =new FileReader("/home/yanshaochen/public/abc.txt");
BufferedReader br = new BufferedReader(fr);
while ((str = br.readLine())!= null) {
System.out.println(str);
}
br.close();
}
}

字节流读写二进制

 public class DataInputStreamDemo {

     public static void main(String[] args) throws IOException {
//原始地址
InputStream is = new FileInputStream("/home/yanshaochen/图片/2017-05-06 15-12-02屏幕截图.png");
DataInputStream dis = new DataInputStream(is);
//目标地址
OutputStream os = new FileOutputStream("/home/yanshaochen/public/2017-05-06 15-12-02屏幕截图.png");
DataOutputStream dos = new DataOutputStream(os);
byte[] bytes = new byte[];
int data;
while((data = dis.read(bytes)) != -){
dos.write(bytes,,data);
}
System.out.println("copy ok!");
dos.close();
dis.close();
}
}

最新文章

  1. 大师教你<部落冲突>如何切换账号
  2. 详解Ossim 4.3控制台
  3. WPS for ubuntu14
  4. 每天一个小算法(matlab armijo)
  5. Mac下安装cocos2d-x环境
  6. HDU 1147 Pick-up sticks
  7. Singleton ——运行时全局唯一对象
  8. shiro基础学习(四)—shiro与项目整合
  9. system进程占用80端口
  10. ireport报表学习
  11. A Deep Learning-Based System for Vulnerability Detection
  12. day09内存管理
  13. Oracle使用学习笔记(一)
  14. Vue.js常用指令:v-bind
  15. DBeaver连接达梦数据库
  16. java-类中需注意的问题
  17. 三、winForm-DataGridView操作——DataGridView 操作复选框checkbox
  18. 快速排序的C++实现
  19. linux shell 脚本攻略学习4
  20. UE4 游戏中csv配置文件使用

热门文章

  1. PyQt QListWidget修改列表项item的行高
  2. try{} catch(…){} 讨论(转)
  3. 浅谈HTTP中Get与Post的区别[转载]
  4. 20155237 2016-2017-2 《Java程序设计》第5周学习总结
  5. 6、CC2541修改按键调节广播发送功率例程为持续发送4DB的蓝牙基站
  6. 深入分析Java单例模式的各种方案
  7. 《c#入门经典第五版》简介及pdf电子书网盘下载地址(收藏)
  8. huffman压缩解压文件【代码】
  9. 浅谈css中单位px和em,rem的区别-转载
  10. folly教程系列之:future/promise