Home Tutorial Java Core Files Java file move

 
 

Share on Google+Share on Google+
Java file move
Posted on: April 28, 2006 at 12:00 AM
Advertisement
In this section, you will learn how to move a file.

Java file move

In this section, you will learn how to move a file.

Description of code:

The package java.io* is based upon streams. Java IO streams provide standardized ways to manipulate file data. Other than read and write, you can perform various file operations.

Basically renameTo() method is used to rename a file but here we have used this method to move a file from one directory to another. You can see in the given example, we have created an object of File class and parse the file with its full path. Now to move this file, we have called renameTo() method through the object of File class. This method consists of another file object, as a parameter, that represents destination path.

Here is the code:

import java.io.File;

public class FileMove {
	public static void main(String[] args) {
		File f = new File("C:/new.txt");
		f.renameTo(new File("C:/Answers/File/new.txt"));
	}
}

Through the renameTo() method, you can move one file from one place to another.

Advertisement

Related Tags for Java file move:


Follow us on Twitter, or add us on Facebook or Google Plus to keep you updated with the recent trends of Java and other open source platforms.

Posted on: April 28, 2006

Recommend the tutorial

Advertisements Advertisements
 

 

 

DMCA.com