import java.io.*;
/**
* @Description: 复制文件,从一个输入流中读取数据,然后通过输出流写入目标位置,一边读一边写
* @ClassName: CopyFile
* @Version: V1.0
*/
public class CopyFile {
private static void copy(String src, String target) {
File srcFile = new File(src);
File targetFile = new File(target);
InputStream in = null;
OutputStream out = null;
try {
in = new FileInputStream(srcFile);
out = new FileOutputStream(targetFile);
byte[] b = new byte[1024];
int len = -1;
while ((len = in.read(b)) != -1) {
out.write(b, 0, len);
}
} catch (FileNotFoundException e) {
e.printStackTrace();
} catch (IOException e) {
e.printStackTrace();
} finally {
try {
if (in != null)
in.close();
} catch (IOException e) {
e.printStackTrace();
}
try {
java文件操作报错:java.io.FileNotFoundException:D..(拒绝访问)
最新推荐文章于 2024-05-02 11:26:31 发布