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的不同分类:
InputStream | OutputStream | Reader | Writer | 抽象类 |
FiledInputStream | FiledOutputStream | FiledReader | FiledWriter | 节点流 子类 |
BufferedInputStream | BufferedOutputStream | BufferedReader | BufferedWriter | 处理流 缓冲流 |
InputStream | OutputStream | 转换流 | ||
ObjectInputStream ObjectOutputStream | 对象流 | |||
RandomAccessFiled | 随机访问流 | |||
System.in System.out | 标准流 | |||
PrintStream | 打印流 | |||
输入流 | 输出流 | 输入流 | 输出流 | |
字节流 | 字符流 |