第十九天:
1,File
2,流的分类 BIO NIO AIO
3,BIO分类:I/O input/output 读/写
1)按流向:输入流 输出流
2)读取方式:字节流 字符流
字节输入流(InputStream) 字节输出流(OutputStream) 字符输入流 字符输出流
4,文件复制
5,加密
6,文件夹复制
编码
ASSIC:0-127
0-32768
GBK
GB2312
utf-8
Test |
import java.io.*; import java.util.Date;
public class Test { public static void main(String[] args) throws Exception { /*try { InputStream is = new FileInputStream("d://a/asd.txt"); //int i = is.read(); byte[] b = new byte[1024];
int i = is.read(b); //is.read(b,0,i); String str = ""; while(i>0){ str += new String(b,0,i); i = is.read(b); } System.out.println(str); } catch (Exception e) { e.printStackTrace(); }*/
/*OutputStream os = new FileOutputStream("d://a/zxc.txt",true); String s = "songxiaobao"; os.write(s.getBytes()); os.flush();*/ long time1 = new Date().getTime(); FileInputStream fis = new FileInputStream("c://rspider.zip"); FileOutputStream fos = new FileOutputStream("c://a/rspider.zip",true); byte[] b = new byte[1024]; int i = fis.read(b); while(i>0){ byte[] bs = new byte[1024]; int index = 0; for(int j=b.length-1;j>=0;j--){ bs[index++] = b[j]; } fos.write(bs,0,i); i = fis.read(b); } fos.flush(); long time2 = new Date().getTime(); System.out.println(time2-time1); } }
|