Moving files in a Directory
Hi,
I would like to move all my files in a directory to another directory ...
I used
Code :
new File("source file path").renameTo(new File("destination file path"));
but i have a trouble giving the path of source and destination files...(not accepting "/" in the path)
can some 1 suggest me a better way to do this
Thanks
Sai=D>
Re: Moving files in a Directory
I guess the issue is resolved
FYI
Code :
import java.io.*;
import javax.swing.*;
public class MovingFile{
public static void main(String[] args) throws IOException{
int a = 0;
BufferedReader in = new BufferedReader(new InputStreamReader(System.in));
System.out.print("Enter the file or directory name that has to be moved : ");
String src = in.readLine();
if(src.equals("")){
System.out.println("Invalid directory or file name.");
System.exit(0);
}
File source = new File(src);
if(!source.exists()){
System.out.println("File or directory does not exist.");
System.exit(0);
}
System.out.print("Enter the complete path where file or directory has to be moved: ");
String dest = in.readLine();
if(dest.equals("")){
System.out.println("Invalid directory or file name.");
System.exit(0);
}
File destination = new File(dest);
if(!destination.exists()){
System.out.print("Mentioned directory does not exist.\nDo you want to create a new directory(Y/N)? ");
String chk = in.readLine();
if(chk.equals("Y") || chk.equals("y")){
destination.mkdir();
copyDirectory(source, destination);
a = 1;
}
else if(chk.equals("N") || chk.equals("n")){
System.exit(0);
}
else{
System.out.println("Invalid Entry!");
System.exit(0);
}
}
:D
Re: Moving files in a Directory
Glad you solved your issue Sai,
You can always try \ instead of /