import java.io.File;
import java.io.FileInputStream;
import java.io.FileNotFoundException;
import java.io.FileOutputStream;
import java.io.IOException;
//编写一个程序,在E盘下创建一个abc.txt的文本文档,
//通过输出流在文档内添加数据,然后在把abc.txt复制到F盘下
public class Lianxi01 {
public static void main(String[] args) throws IOException {
String a = "这个文件要从e盘复制到f盘";
byte[] b = a.getBytes();
FileOutputStream fos = new FileOutputStream("E:\\abc.txt");
fos.write(b);
fos.close();
}
}
____________________________分割线_____________________________________________________________________
package com.zhidi.lianxi;
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 = "这个文件要从e盘复制到f盘";
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();
}
}