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?

[330 byte] By [toyewamidea] at [2007-11-27 6:03:18]
# 1
Drag and drop tutorial: http://java.sun.com/docs/books/tutorial/uiswing/dnd/index.html
Hippolytea at 2007-7-12 16:45:56 > top of Java-index,Java Essentials,Java Programming...
# 2
Accessing and moving files on the local hard drive is generally not a problem for Java, however dragging and dropping a Windows Icon onto a Java program will prove to be near impossible.
maple_shafta at 2007-7-12 16:45:56 > top of Java-index,Java Essentials,Java Programming...
# 3
I've gotten to the point that i can drag an icon to the app and get the full path of the file. It tells me the possible flavor,but it doesnt move the file to the new destination.
toyewamidea at 2007-7-12 16:45:56 > top of Java-index,Java Essentials,Java Programming...
# 4
What code did you write to move the file?
Hippolytea at 2007-7-12 16:45:56 > top of Java-index,Java Essentials,Java Programming...
# 5

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);

toyewamidea at 2007-7-12 16:45:56 > top of Java-index,Java Essentials,Java Programming...
# 6
Try calling renameTo once instead of twice.
Hippolytea at 2007-7-12 16:45:56 > top of Java-index,Java Essentials,Java Programming...
# 7
> 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)
jsalonena at 2007-7-12 16:45:56 > top of Java-index,Java Essentials,Java Programming...
# 8
Test folder exist, but the text file doesnt exist.
toyewamidea at 2007-7-12 16:45:56 > top of Java-index,Java Essentials,Java Programming...
# 9

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

jsalonena at 2007-7-12 16:45:56 > top of Java-index,Java Essentials,Java Programming...
# 10

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

toyewamidea at 2007-7-12 16:45:56 > top of Java-index,Java Essentials,Java Programming...