-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathFileMove.java
More file actions
36 lines (32 loc) · 863 Bytes
/
Copy pathFileMove.java
File metadata and controls
36 lines (32 loc) · 863 Bytes
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
// renaming and moving a file from one directory to another
import java.util.Scanner;
import java.io.*;
import java.nio.file.Files;
import java.nio.file.*;
class FileMove
{
public static void main(String args[]) throws IOException
{
Scanner scan = new Scanner(System.in);
System.out.println("Enter Source file name");
String sname = scan.nextLine();
System.out.println("Enter Dest. Directory and file name");
String dname = scan.nextLine();
File f = new File(sname);
if(f.exists()&&f.isFile()==true)
{
Path temp = Files.move(
Paths.get(sname),Paths.get(dname)
);
if(temp != null)
System.out.println("File renamed and moved successfully.");
else{
System.out.println("Unable to move file");
}
}
else
{
System.out.println("File not found!");
}
}
}