Reputation: 67
I'm trying to move a file with processing.
import java.util.Base64;
import java.io.*;
import java.nio.file.Files;
import java.nio.file.Paths;
String source = "C:\test\1.jpeg";
String newdir = "C:\test123\1.jpeg";
void setup() {
Files.move(source, newdir.resolve(source.getFileName()));
}
I took a look at this and tried to make it work, however I get an error that The function getFileName() does not exist. I looked for this also, but didn't find much. Could someone point me into the right direction for moving a file from one dir to another?
Upvotes: 1
Views: 352
Reputation: 5859
Take a look at this:
import java.nio.file.*;
String source = "C:\\test\\1.jpeg";
String newdir = "C:\\test123\\1.jpeg";
void setup() {
try {
Path temp = Files.move(Paths.get(source), Paths.get(newdir));
} catch (IOException e) {
print(e);
}
}
Couple of points - use \\
instead of a single \
when specifying the paths. Secondly, getFileName()
can only be applied to a Path object, not a String, and that caused your error in the question. Same, by the way, with the resolve(String s)
method, it can only be applied to a Path, not String.
Using Paths:
import java.nio.file.*;
Path source = Paths.get("...");
Path newdir = Paths.get("...");
void setup() {
try {
Files.move(source, newdir);
} catch (IOException e) {
print(e);
}
}
Upvotes: 3