Java Program for Moving a file from current directory.
import java.io.*;
class Abcd
{
public static void main(String args[])
{
try{BufferedReader br=new BufferedReader(new InputStreamReader(System.in));
String sr=System.getProperty("user.dir");
File file = new File(sr+\\invent.dat);
// Destination directory
File dir = new File("E:\\java");
// Move file to new directory
boolean success = file.renameTo(new File(dir, file.getName()));
if (!success) { System.out.print("\n Error");//File Not FOund or any other error
}
System.out.print("\n Directory is "+sr);
br.readLine();}catch(Exception e){}
}
}
Loading...
|
Comments :
Post a Comment