FileInputStream / FileOutputStream 文件字节流
public class filecopy
{
public static void main(String [] args) throws IOException{
File fin=new File("intext.txt");
File fout=new File("outtext.txt");
FileInputStream in = new FileInputStream(fin);
FileOutputStream out = new FileOutputStream(fout);
while((c=in.read())!=-1)
{
out.write();
}
in.close();
out.close();
}
}
==========================================================================
FileReader / FileWriter() 文件字符流
public class filecopy
{
public static void main(String [] args) throws IOException {
File fin =new File("fin.txt"); //创建输入文件对象
File fout=new File("fout.txt"); //创建文件输出对象
FileReader in = new FileReader(fin); //创建文件字符流 读 对象,传递文件对象
FileWriter out = new FileWriter(fout); //创建文件字符流 写 对象,传递文件对象
int c;
while((c=in.read())!=-1) //读
{
out.writer(); //写
}
in.close();
out.close();
}
}
FileWriter out = new FileWriter(fout); FileWriter()中的对象可以是 文件对象,也可以是文件URL