📄 copyfile.java
字号:
package com.khan.file;
import java.io.FileInputStream;
import java.io.FileOutputStream;
/**
*
* <p>Title: 文件操作类</p>
*
* <p>Description: </p>
*
* <p>Copyright: Copyright (c) 2006</p>
*
* <p>Company: </p>
*
* @author not attributable
* @version 1.0
*/
public class CopyFile {
/**
* copy 文件
* @param source_file String
* @param target_file String
* @return boolean
*/
public boolean copy(String source_file, String target_file) {
try {
java.io.File file_in = new java.io.File(source_file);
java.io.File file_out = new java.io.File(target_file);
FileInputStream in1 = new FileInputStream(file_in);
FileOutputStream out1 = new FileOutputStream(file_out);
byte[] bytes = new byte[1024];
int c;
while ((c = in1.read(bytes)) != -1) {
out1.write(bytes, 0, c);
}
in1.close();
out1.close();
return (true); //if success then return true
} catch (Exception e) {
System.out.println("Error!");
return (false); //if fail then return false
}
}
/**
* 删除文件
* @param file_name String
* @return boolean
*/
public boolean delete(String file_name){
boolean result = false;
java.io.File file = new java.io.File(file_name);
if(file.exists()){//检查File.txt是否存在
file.delete(); //删除File.txt文件
result = true;
}
return result;
}
}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -