java move file to directory code example

Example: Move a file from one directory to another using java

// Move a file from one directory to another using java
import java.io.IOException;
import java.nio.file.Files;
import java.nio.file.Path;
import java.nio.file.Paths;
public class JavaMoveFile
{
   public static void main(String[] args) throws IOException
   {
      Path move = Files.move(Paths.get("B:\flowerbrackets.txt"), Paths.get("B:\Softs\flowerbrackets.txt"));
      if(move != null)
      {
         System.out.println("File moved successfully");
      }
      else
      {
         System.out.println("Failed to move the file");
      }
   }
}

Tags:

Java Example