我用Java来复制文件,但它出现异常(系统找不到指定的文件).
代码是
public static void copyFile(String sourceFile, String destFile){
try {
InputStream in = new FileInputStream(sourceFile);
OutputStream os = new FileOutputStream(destFile);
byte[] buffer = new byte[1024];
int count;
while ((count = in.read(buffer)) > 0) {
os.write(buffer, 0, count);
}
in.close();
os.close();
} catch (IOException e) {
e.printStackTrace();
}
}
Run Code Online (Sandbox Code Playgroud)
测试代码
public static void main(String[] args) {
String name = getFileName("D:/z/temp.txt");
String target = "D:/tem.txt";
copyFile(name, target);
}
Run Code Online (Sandbox Code Playgroud)
例外是 java.io.FileNotFoundException: temp.txt(the system can not find the file specified)
我猜这是权限问题.谁能想出答案谢谢!
| 归档时间: |
|
| 查看次数: |
852 次 |
| 最近记录: |