如何给args [0]中的源文件和args [1]中的目标文件?我在同一个包中创建了一个source.txt和一个target.txt,并在运行配置中放入了“./source.txt”和“./target.txt”作为参数。但它会抛出“./source.txt”不可读取的异常。Paths.get(args [0])不起作用
Exception in thread "main" java.lang.IllegalArgumnetException: ./source.txt
什么是worng?
import java.io.IOException;
import java.nio.file.Files;
import java.nio.file.Path;
import java.nio.file.Paths;
import java.nio.file.StandardCopyOption;
import de.sb.javase.TypeMetadata;
/**
* Demonstrates copying a file using a single thread.
*/
public final class FileCopyLinear {
/**
* Copies a file. The first argument is expected to be a qualified source file name,
* the second a qualified target file name.
* @param args the VM arguments
* @throws IOException if there's an I/O related problem
*/
public static void main(final String[] args) throws IOException {
final Path sourcePath = Paths.get(args[0]);
if (!Files.isReadable(sourcePath)) throw new IllegalArgumentException(sourcePath.toString());
final Path sinkPath = Paths.get(args[1]);
if (sinkPath.getParent() != null && !Files.isDirectory(sinkPath.getParent())) throw new IllegalArgumentException(sinkPath.toString());
Files.copy(sourcePath, sinkPath, StandardCopyOption.REPLACE_EXISTING);
System.out.println("done.");
}
}
“./source.txt” 不readdable?我希望实现者不会犯这种拼写错误。总是复制粘贴原始堆栈跟踪 – 2013-04-23 10:01:58
什么是“异常”的详细信息(类型,消息,合理详细的堆栈跟踪)? – 2013-04-23 10:02:37
是不是args [0]你正在擅长的.java文件?还是仅仅在C++中? – 2013-04-23 10:03:38