编写一个程序,在E盘下创建一个abc.txt的文本文档,通过输出流在文档内添加数据,然后在把abc.txt复制到F盘下
import java.io.FileInputStream;
import java.io.FileNotFoundException;
import java.io.FileOutputStream;
import java.io.IOException;
public class Test {
public FileInputStream fis;
public FileOutputStream fos;
public static void main(String[] args) throws IOException {
Test t = new Test();
t.create();
t.copy();
}
public void create() throws IOException{
fos = new FileOutputStream("E:\\abc.txt");
String s = "这是写入的内容";
fos.write(s.getBytes());
fos.close();
}
public void copy() throws IOException{
fis = new FileInputStream("E:\\abc.txt");
byte[] b = new byte[1024];
int len = fis.read(b);
String s = new String(b,0,len);
fos = new FileOutputStream("F:\\abc.txt");
fos.write(s.getBytes());
fos.close();
fis.close();
}
}