zoukankan      html  css  js  c++  java
  • 02026_字符流练习

    1、练习:复制文本文件

    2、思路:

      (1)既然是文本涉及编码表。需要用字符流;

      (2)操作的是文件。涉及硬盘;

      (3)有指定码表吗?没有,默认就行。

     1 import java.io.FileReader;
     2 import java.io.FileWriter;
     3 import java.io.IOException;
     4 
     5 public class CopyTextFileTest {
     6     public static void main(String[] args) throws IOException {
     7         copyTextFile();
     8     }
     9 
    10     public static void copyTextFile() throws IOException {
    11         // 1,明确源和目的。
    12         FileReader fr = new FileReader("d:\Java\cn.txt");
    13         FileWriter fw = new FileWriter("d:\Java\copy.txt");
    14         // 2,为了提高效率。自定义缓冲区数组。字符数组。
    15         char[] buf = new char[1024];
    16         int len = 0;
    17         while ((len = fr.read(buf)) != -1) {
    18             fw.write(buf, 0, len);
    19         }
    20         /*
    21          * 2,循环读写操作。效率低。 int ch = 0; while((ch=fr.read())!=-1){ fw.write(ch); }
    22          */
    23         // 3,关闭资源。
    24         fw.close();
    25         fr.close();
    26     }
    27 }
  • 相关阅读:
    token原理
    1.系统代码读取配置文件
    redis hash怎么用
    那么都数据库表,那么多不同记录。是怎样都存储在一个key-value数据库的?
    jedis操作redis全指南
    redis列表list
    jedis操作
    redis
    android raw与assets资源
    Zoie Merge Policy
  • 原文地址:https://www.cnblogs.com/gzdlh/p/8097314.html
Copyright © 2011-2022 走看看