package com.heima.gaoshuai.io;
import java.io.BufferedInputStream;
import java.io.BufferedOutputStream;
import java.io.File;
import java.io.FileInputStream;
import java.io.FileOutputStream;
public class IOTest {
public static void main(String[] args) throws Exception {
}
//standard
public static void demo03()throws Exception{
FileInputStream fis = new FileInputStream("a.txt");// a.txt
// (系统找不到指定的文件。)
FileOutputStream fos = new FileOutputStream("b.txt");
int b = 0;
//fis.read(byte[]);
if ((b = fis.read()) != -1) {// read()/read(byte)
fos.write(b);
}
fis.close();
fos.close();
}
public static void demo02() throws Exception{
// String str = "C:\\Users\\Administrator\\Desktop";
// File file = new File(str);
FileInputStream fis = new FileInputStream("C:\\Users\\Administrator\\Desktop\\新建文本文档 (3).txt");
FileOutputStream fos = new FileOutputStream("新建文本文档 (3).txt");//file dest
BufferedInputStream bis = new BufferedInputStream(fis);
BufferedOutputStream bos = new BufferedOutputStream(fos);
int a = 0;
while((a=bis.read())!=-1){//read a个
bos.write(a);//write
}
bis.close();
bos.close();
}
public static void demo01() throws Exception{
// 字节输入流 程序
FileInputStream fis1 = new FileInputStream("a.txt");
byte[] bytes = new byte[3];// 字节截取,乱码
int len = 0;
while (-1 != (len = fis1.read(bytes))) {//read();/fis1.read();字节的asicc码表值
String str1 = new String(bytes);
System.out.print(str1);
}
// 字节输出流
FileOutputStream fos1 = new FileOutputStream("b.txt");
String str2 = "中国";
byte[] bytes1 = str2.getBytes();
fos1.write(bytes1);
}
}
|
|