计算机基础

IO   Input: 输入    Output:输出

IO的事例如下:

//复制文件夹

import java.io.File;
import java.io.FileInputStream;
import java.io.FileOutputStream;
import java.io.IOException;
import java.io.InputStream;
import java.io.OutputStream;

public class Text2 {
	public static void main(String[] args) {
		File file =  new File("D:\\aa");
		File dest =  new File("D:\\aa1");
		print(file,dest);
	}
	public static void print( File file,File dest ) {
		//建一个新的文件夹
		dest.mkdir();
		//获取文件夹中所有的文件和文件夹,数组
		File[] files = file.listFiles();
		//遍历
		for(File f:files) {
			//父目录的绝对路径
			String str1 = dest.getAbsolutePath();
			//是文件夹
			if(f.isDirectory()) {
				//当前文件夹的名字
				String str = f.getName();
				//新地址
				File newfile = new File(str1+"/"+str);
				print(f,newfile);
			}else {
				String str = f.getName();
                                //调用复制文件的方法
				copy(f,str1+"/"+str);
			}
		}
	}
        //复制文件
	public static void copy( File file,String string) {
		InputStream is = null;
		OutputStream os = null;
		try {
			is = new FileInputStream(file);
			os = new FileOutputStream(string);
			byte[] b = new byte[2];
			int len = 0;
			while((len = is.read(b))!=-1) {
				String s = new String(b,0,len);
				s = s.toUpperCase();
				os.write(s.getBytes());
			}
		}catch (Exception e) {
			e.printStackTrace();
		}finally {
			try {
				os.close();
			} catch (IOException e) {
				// TODO Auto-generated catch block
				e.printStackTrace();
			}
			try {
				is.close();
			} catch (IOException e) {
				// TODO Auto-generated catch block
				e.printStackTrace();
			}
		}
		
	}
}

IO的不同分类:

InputStreamOutputStreamReaderWriter抽象类
FiledInputStreamFiledOutputStreamFiledReaderFiledWriter

节点流

子类

BufferedInputStreamBufferedOutputStreamBufferedReaderBufferedWriter处理流   缓冲流
InputStreamOutputStream  转换流
ObjectInputStream         ObjectOutputStream   对象流
                                RandomAccessFiled随机访问流
System.in                        System.out标准流
                                  PrintStream打印流
输入流输出流输入流输出流 
字节流字符流 

 

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值