📄 copyfile.java
字号:
//源文件名:copyFile.java
//在下载源程序中的文件夹:1006复制文件
import java.io.*;
public class copyFile
{
public static void main(String args[]) throws IOException
{
File f1,f2;
f1 = new File(".","sourceFile.txt");
f2 = new File(".\\subDir","targetFile.txt");
copy(f1,f2);
System.exit(0);
}
public static void copy(File f1,File f2) throws IOException
{
FileInputStream rf = new FileInputStream(f1);
FileOutputStream wf = new FileOutputStream(f2);
int count,n=512;
byte buffer[] = new byte[n];
count = rf.read(buffer,0,n);
while (count != -1)
{
wf.write(buffer,0,count);
count = rf.read(buffer,0,n);
}
System.out.println("已经把文件“"+f1.getPath()+"”复制为“"+f2.getPath()+"”");
rf.close();
wf.close();
}
}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -