I want to be able to use a variable that can be changed within a file path. The username relevant to the file path is declared in the constructor then I have tried to assign this to the file path in the below method.
What I wanted to happen when calling:
System.out.format("%s%n", documentsPath.resolve(username +"\\Documents"));
Was that the documents Path would then be:
C:\Users\ryanb\Documents
Instead when I call documentsPath.toString() I only get returned:
C:\Users\
How do I get the documentsPath variable to be assigned with the String username and the "\\Documents" at the end.
This is my code:
class profileCopy{
/*global variables */
private Path documentsPath;
private Path desktopPath;
private Path favoritesPath;
private Path networkFolder;
private String username;
private String foldername;
public profileCopy(String username, String foldername)
{
this.username = username;
this.foldername = foldername;
documentsPath = Paths.get("C:\\Users");
desktopPath = Paths.get("C:\\Users");
favoritesPath = Paths.get("C:\\Users");
networkFolder = (Paths.get("F:\\Data\\WP51"));
}
public void copyDocumentsFolder() throws IOException
{
Path newDir = Paths.get("C:\\Users\\ryanb\\Documents\\TestCopy");
System.out.format("%s%n", documentsPath.resolve(username +"\\Documents"));
System.out.format("%s%n", networkFolder.resolve(foldername + "\\Backup"));
System.out.println(networkFolder.getFileName());
Files.move(documentsPath, networkFolder.resolve(documentsPath.getFileName()));
System.out.println(newDir.toString());
}