Reputation: 1492
I have an issue where I want to copy Files from one directory to another directory.
Path source = Paths.get(files[i].getPath());
Path target = Paths.get(dir.getName() + "/" + files[i].getName());
try {
Files.copy(source, target, StandardCopyOption.REPLACE_EXISTING);
files[i] = target.toFile();
} catch (IOException e) {
throw new IOException("\t\tUnable to move " + files[i].getName(), e);
}
This code does work, however I am running JRE 1.8, while the system on which I want to run it is running JRE 1.6. Both Path and Files were only available since JRE 1.7.
Is there a way I can use eclipse or the java compiler to package these classes with my jar file.
Upvotes: 1
Views: 114
Reputation: 1275
Normally you can use -target option to generate class files that target a specified version of the VM. ex: javac -target 1.6. Look here for more options. But this doesn't work when there are classes in the source code which are not available to the target you specify. I believe you use java File IO api and minimum target you can use is 1.7.
If you feel comfortable with the command line, you can try to run OS commands in your Java code. In my opinion it is much easier than trying to rewrite the File and Path java classes. At least that's what I did.
You can find good examples here if you don't know how to execute OS commands in your Java code.
Upvotes: 2