Or you could try something like.... (note: error handling in this
quick example isn't ideal and also if your file is a simple txt file
there are other ways to do it more efficiently )
import java.io.*;
public class FileMove
{
public static void main( String[] args )
{
try {
File fileToMove = new File( "C:\\RicksStuff\\seinfeld.exe" );
File moveTo = new File( "C:\\RicksStuff\\newDir\\seinfeld.exe" );
if ( !moveTo.exists() )
moveTo.createNewFile();
BufferedInputStream inputFromFile = new BufferedInputStream( new
FileInputStream( fileToMove ) );
BufferedOutputStream outputToFile = new BufferedOutputStream( new
FileOutputStream( moveTo ) );
int i = inputFromFile.read();
while ( i != -1 )
{
outputToFile.write(i);
i = inputFromFile.read();
}
outputToFile.close();
inputFromFile.close();
}
catch(Exception e ) {
System.out.println( e.toString() );
}
}
}
On 27 Aug 2001, at 14:00, Alireza Nahavandi wrote:
> Hi All,
> Does anybody know how to copy a file to another folder using Java?
>
> Thank you,
>
> ===========================================================================
> To unsubscribe: mailto [EMAIL PROTECTED] with body: "signoff JSP-INTEREST".
> For digest: mailto [EMAIL PROTECTED] with body: "set JSP-INTEREST DIGEST".
> Some relevant FAQs on JSP/Servlets can be found at:
>
> http://java.sun.com/products/jsp/faq.html
> http://www.esperanto.org.nz/jsp/jspfaq.html
> http://www.jguru.com/jguru/faq/faqpage.jsp?name=JSP
> http://www.jguru.com/jguru/faq/faqpage.jsp?name=Servlets
--
I'd like to be buried Indian-style, where they put you up on a high
rack, above the ground. That way, you could get hit by meteorites and
not even feel it.
- Jack Handey
===========================================================================
To unsubscribe: mailto [EMAIL PROTECTED] with body: "signoff JSP-INTEREST".
For digest: mailto [EMAIL PROTECTED] with body: "set JSP-INTEREST DIGEST".
Some relevant FAQs on JSP/Servlets can be found at:
http://java.sun.com/products/jsp/faq.html
http://www.esperanto.org.nz/jsp/jspfaq.html
http://www.jguru.com/jguru/faq/faqpage.jsp?name=JSP
http://www.jguru.com/jguru/faq/faqpage.jsp?name=Servlets