Don't use literal "/". Use File.separator, or better yet:
new File( file.getParent(), n )
Also, file.getParent() could be null or empty, and you're not taking
that into account. Nor are you taking null or empty n values into
account.
file.renameTo(new File(n));
This line has 2 bugs:
1. You're not checking whether renameTo() worked or not.
2. You're making a File from n as if it were a complete pathname,
when it might not be. I think this is the cause for your example
failing. I'm guessing it should be something like:
file.renameTo(t);
and you should do something useful with the returned boolean.
My personal choice would be to throw an IOException if renameTo() is
false, but others may feel that returning the boolean from renameSelf
() is more appropriate. Ignoring the success or failure of
file.renameTo() is simply wrong.
File newFile = new File(dest.getPath() + "/" + file.getName());
Again, you're pasting in "/" when you should use File.separator or
the new File(File,String) constructor.
You would benefit by debugging your code and stepping through it,
inspecting the local and instance variables as each statement
executes. I think this would show why your failing example fails.
If you don't know how to use the debugger for stepping or variable
inspection, and don't want to learn how, you should at least learn
how to "debug by printing", i.e. liberally adding statements like:
System.out.println( "at 2, x = " + x );
where 2 is a sequence number (1, 2, 3, ...) and x is some variable of
interest, such as t or n or the instance variable 'file' in your Item
class.
-- GG
_______________________________________________
Do not post admin requests to the list. They will be ignored.
Java-dev mailing list (email@hidden)
Help/Unsubscribe/Update your Subscription:
http://lists.apple.com/mailman/options/java-dev/email@hidden