http://www.verejava.com/?id=16994676228912
package com.io;
import java.io.*;
public class TestCopy
{
public static void main(String[] args)
{
InputStream is=null;
OutputStream os=null;
try
{
//读取文件 english.txt
is=new FileInputStream(new File("res/1.png"));
//实列化一个写入流
os=new FileOutputStream(new File("res/copy.png"));
int l;
//一边读 一边写入
while((l=is.read())!=-1)
{
os.write(l);
}
}
catch (Exception e)
{
e.printStackTrace();
}
finally
{
try
{
is.close();
os.close();
}
catch (IOException e)
{
e.printStackTrace();
}
}
}
}

本文提供了一个使用Java进行文件复制的简单示例。通过InputStream从源文件读取字节,并通过OutputStream将这些字节写入目标文件,实现了从res/1.png到res/copy.png的文件复制。
3036

被折叠的 条评论
为什么被折叠?



