File类的代码:
  | 
IO流:
1.按读写基本单位分:字节流(以字节读写),字符流(以2 字节读写,止咳读取文本文件,只能有文字)
2.按数据流动方向:输入流(将文件内容输入到程序中,读),输出流(将程序内容输出到文件,写)
3.节点流(直接与文件关联),包装流(需要依赖别的流)
FileOutPutStream():
方法:
void write(int b) –将 指定字节写入文件输出流
void write(byte[],int of,int len)–指定数组从偶读开始到len长个字节写入输出流
void write(byte[])– 写一个数组
void close()–关闭输出流释放资源
要将字符串变成数组用getByte(),例:
ts.write("helloyou".getByte());
FileInPutStream():
方法:
int read() –读取单个字符,返回-1就读到了最后;
int read(byte[]) –读取数组,返回的是字符个数
int read(byte[],int of,len )–读取数组里从of开始的len个字节
void close()–关闭流
文件拷贝的方法:
package day17;
import java.io.FileInputStream;
import java.io.FileOutputStream;
public class WanSua {
      public static void main(String[] args) {
        try {
            FileInputStream fis = new FileInputStream("e:/A.txt");
            FileOutputStream fos = new FileOutputStream("d:/b.txt");
         //第一种用法:
            int re = 0;
            while((re=fis.read())!=-1) {
                fos.write(re);
         //第二种用法:
          int len = fis.available() ;//此关键字是将缓冲区内容一次性获取
            byte [] arr =new byte[len];    
             int re2=0;
                while((re2=fis.read())!=-1){
                    fos.write(arr);
         //第三种用法:
            byte [] brr =new byte[1024*8];
            int re3=0;
            while((re3=fis.read())!=-1) {
                fos.write(brr, 0, re3);
            }
                }     
            }             
        } catch (Exception e) {
            e.printStackTrace();
        }
      }
}
···