aspose file tools*
The moose likes Java in General and the fly likes Moving File From One Directroy to Another Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login
JavaRanch » Java Forums » Java » Java in General
Bookmark "Moving File From One Directroy to Another" Watch "Moving File From One Directroy to Another" New topic
Author

Moving File From One Directroy to Another

amogh deshpande
Greenhorn

Joined: Feb 20, 2007
Posts: 14
Hi All,
Below is the code for moving file from one directory to another
and its working very fine when i run it as separate class.
but if i am trying to call the method movefile throgh run method of the thread ,it is returning false value since reName method which is used here returns boolean value..
i am stuked becoz of this.Its giving prb only if i am calling this method (movefile)throgh thread.
so if any body can help me out..

Thanks a lot?
Below is the code for moving fiel from one directory to another...


//******************************************************************
package com.bj;

import java.io.*;

public class Move
{


public void moveFile(String src)
{
String ss = src;
File file = new File(ss);
System.out.println("+++++++++++++++++++++"+file);
// Destination directory
File dir = new File("C://output//");
System.out.println(dir);
// Move file to new directory
File gg = new File(dir, file.getName());
System.out.println("||||||||||||||||||||"+gg);
try
{
boolean success = file.renameTo(gg);
System.out.println(success);
}
catch(SecurityException ex )
{
System.out.println("Exception while Renaming File" +ex);
}



}
}
//**************************************************************************
and this is the code from where i am calling method
//*******************************************************
package com.bj;

import java.io.*;
import java.text.SimpleDateFormat;
import java.util.*;
import java.io.FileReader;

public class Polling extends Thread{
//private Store store;
//int fint;


public void run()
{

Move mv = new Move();
mv.moveFile(s1);

}


//*******************************************************
Peter Chase
Ranch Hand

Joined: Oct 30, 2001
Posts: 1970
What are those double forward-slashes supposed to do? On Windows, you should use back-slash, which requires a double back-slash in a Java String literal. You can get away with a single forward slash most of the time, too.

Also, does the "output" directory exist?


Betty Rubble? Well, I would go with Betty... but I'd be thinking of Wilma.
amogh deshpande
Greenhorn

Joined: Feb 20, 2007
Posts: 14
Originally posted by Peter Chase:
What are those double forward-slashes supposed to do? On Windows, you should use back-slash, which requires a double back-slash in a Java String literal. You can get away with a single forward slash most of the time, too.

Also, does the "output" directory exist?


Yes Output Directory is there.ya i have tried with \\ also..
i am calling start()
from run ()
i dont know is there any prb coz of this

Thank you!
Vlado Zajac
Ranch Hand

Joined: Aug 03, 2004
Posts: 245
File.renameTo will likely fail when moving from one disk partition to another (e.g. from C: do D . It can also fail when destination already exists and it will obviously fail when source file does not exist or is the user does not have required access rights.
 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: Moving File From One Directroy to Another