我已经从许多地方复制了被认为是使用 Java 7 将文件从 A 复制到 B 的正确脚本。我已经下载了 Java 7,并且在运行该页面时绝对没有任何反应。我正在做(或者可能没有做)一些非常基本但错误的事情。你能告诉我我需要什么吗?我正在使用这个脚本:
<?xml version="1.0" encoding="utf-8"?>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0
Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml" xml:lang="en" lang="en">
<head>
<title></title>
<meta http-equiv="content-type" content="text/html; charset=utf-8" />
<meta name="generator" content="CoffeeCup HTML Editor (www.coffeecup.com)" />
<meta name="created" content="Sun, 17 Feb 2013 15:50:39 GMT" />
<meta name="description" content="" />
<meta name="keywords" content="" />
</head>
<body>
<Script>
import java.io.File;
import java.io.IOException;
import java.nio.file.Files;
import java.nio.file.StandardCopyOption;
public class Copier {
public static void main(String[] args) throws IOException {
//Copy file /foo/x.txt to /bar directory
String source = "C:/Users//Mike/test.txt";
String target = "C:/Users/Mike/test1.txt";
Copier.copyFile(source, target);
}
public static void copyFile(String source, String target) {
try {
Files.copy(new File(source).toPath(), new File(target).toPath(),
StandardCopyOption.REPLACE_EXISTING);
} catch (IOException e) {
e.printStackTrace();
}
}
}
</script>
</body>
</html>