samedi 28 mai 2016

Trying to copy an image file and move it to a new folder that is dynamically created. java web [duplicate]

This question already has an answer here:

Trying to copy an image file and place it in a new folder that is generated dynamically. Not sure why the file is not being created? The folder gets created under the username of the currently logged in user but the image does not copy across. Any ideas why this is happening? Thanks for your attention.

public String directoryAbsolute = "C:/Users/jonathanlal/workspace/jonaProjects/testproject/WebContent/UserFiles";

public File defaultcover = new File("C:/Users/jonathanlal/workspace/jonaProjects/testproject/WebContent/img/cover.png");

String username=request.getParameter("username");


String fileName = username+"_"+"cover.png"; 
File folderdestination = new File("C:/Users/jonathanlal/workspace/jonaProjects/testproject/WebContent/UserFiles" +  username  + File.separator + fileName);

String directory = directoryAbsolute + File.separator + username;;
                        File fileSaveDir = new File(directory);
                        if (!fileSaveDir.exists()) {
                            fileSaveDir.mkdir();
                            Path test = Files.copy(defaultcover.toPath(), folderdestination.toPath());
                            Files.createFile(test);


                        }




Aucun commentaire:

Enregistrer un commentaire