Moving and renaming image files
I want to move & rename image files to folders on the hard drive by dragging and dropping them into my application. I read about the problem with renameTo() method with windows. Is this possible to do in java? I heard about a method in which you read,write and delete the old file? How do I go about making this happen?
File newdest= new File(file.getText());
File dir= new File("C:/Test/testfile1.txt");
newdest.renameTo(new File(dir,newdest.getName()));
boolean ans=newdest.renameTo(new File(dir,newdest.getName()));
System.out.println(ans);
System.out.println(newdest);
> newdest.renameTo(new File(dir,newdest.getName()));Does the directory called C:/Test/testfile1.txt exist?(By the way, the character "." is not very common in directory names on Windows)
Well, what happens if you create the folder C:/Test/testfile1.txt ?
Or alternatively remove the part that says "testfile1.txt" from the directory path in your program.
Or alternatively call dir.mkdirs() before trying to rename.
What I am getting at is that when you create a file with the constructornew File(dir,newdest.getName())
the parameter dir is treated as a directory no matter what its name is. If its name is "C:/Test/testfile1.txt," the name of the new file will be "C:/Test/testfile1.txt/name_of_newdest"
where name_of_newdest is the name of the "newdest" file. This might not be what you wanted
Hey everybody,
I found an example thats kinda close to what I was looking for.
Check out this page: http://schmidt.devlib.org/java/copy-file.html It shows you how to copy a file and move it to another directory,but you will have to modify it to be able to :
* use a Drag and Drop files ( I havent tried it yet.)
* change the filename ( i havent tried it yet)
* Make it a GUI program