package what;
import java.io.*;
public class Example
{
public void copy() throws IOException
{
String filePath="E:/编程程序/what/test.txt"; //文件path
String dirPath="E:/编程程序/what复制件"; //目录path
try(FileInputStream input=new FileInputStream(filePath);
FileOutputStream output=new FileOutputStream(dirPath+File.separator+filePath.substring(dirPath.lastIndexOf("/"))))
{
byte[] bbuf=new byte[1024];
int hasRead=0;
while((hasRead=input.read(bbuf))>0)
{
output.write(bbuf,0,hasRead);
}
}
catch(Exception ioe)
{
ioe.printStackTrace();
}
}
public static void main(String[] args) throws IOException
{
new Example().copy();
}
}
把指定的文件复制到目标文件夹下
最新推荐文章于 2023-12-20 15:16:45 发布