Move File

ตัวอย่าง code การ ย้ายไฟล์

/**
 * File Name : MoveFile.java
 * Created Date : Nov 12, 2009 : 10:39:43 AM
 * Copyright © 2009 www.fun4station.com
 */
package com.fun4station.example;

import java.io.File;

/**
 * @Author Supot Saelao 
 * @Version 1.0
 */
public class MoveFile {

	public static void main(String[] args) {
		File file = new File("fileMove.txt");
		File dir = new File("C:/data");
		
		//If want to change new file name
		String newFileName = file.getName();
		
		if(file.renameTo(new File(dir, newFileName))){
			System.out.println("Move file success....");
		}else{
			System.out.println("Move file fail....");
		}
	}

}

ข้อมูลจาก
Moving a File or Directory to Another Directory

  1. No comments yet.

  1. No trackbacks yet.