-2

I am trying to move failed files to different directory(not copying, but moving).

 originalfilename.renameTo(new File("C"));

It's giving me that renameTo is undefined for type String. Why am I getting this? Is there any other simpler API or statements to acheive this?

EDIT:How to move to different directory rather than creating a new file?

1 Answers1

1

renameTo is a method of the File class, you are trying to use it on a String.

File original = new File(originalfilename);
original.renameTo(new File("C"));
Gabriel Negut
  • 13,860
  • 4
  • 38
  • 45
  • how do I make it a directory instead of "file"? When I do this, it's making a new file instead of a folder. – user2482974 Jun 13 '13 at 16:37
  • @user2482974 if this is Java 7, drop `File`; see the `Files` class, it has all you want – fge Jun 13 '13 at 16:42